The solution to the focus of Android's ListView and TextView

Source: Internet
Author: User

Find a lot of articles on the web, that is in the XML file set TextView focus is false, it is nonsense, so even the text can not input, what is the use of

Search online without results, use Java code to control the ListView Longclick method, to implement pop-up replication and delete ListView methods

Customizing a Popwindow

private void Initpopupwindow (Layoutinflater inflater) {
View view = Inflater.inflate (r.layout.pop_item_layout, NULL);
Popupwindow = new Popupwindow (view, 100, 50);
popupwindow.setwidth (layoutparams.wrap_content);
popupwindow.setheight (layoutparams.wrap_content);
Copytv = (TextView) View.findviewbyid (R.ID.POP_COPY_TV);
Deletetv = (TextView) View.findviewbyid (R.ID.POP_DELETE_TV);
}


and write a listening method on your own.

Class Tvontouch implements Ontouchlistener {
Private Context Mcontext;
private int mposition;


Public Tvontouch (context context, int position) {
TODO auto-generated Method Stub
This.mcontext = context;
This.mposition = position;
}


@Override
public boolean OnTouch (View V, motionevent event) {
TODO auto-generated Method Stub
if (v.getid () = = R.id.pop_copy_tv) {
TextView TV = (TextView) v;
if (event.getaction () = = Motionevent.action_down) {//Press
Tv.settextcolor (0xff00cd66);
} else if (event.getaction () = = motionevent.action_up) {//Bounce up
Tv.settextcolor (0xFFFFFFFF);

Com.robot.utils.TextManager.copyText (Mcontext, Mdatas.get (mposition). getmsg ());
Toast.maketext (Mcontext, "Copy succeeded", Show_time). SHOW ();


if (Popupwindow! = null) {
Popupwindow.dismiss ();
}
}
} else {
TextView TV = (TextView) v;
if (event.getaction () = = Motionevent.action_down) {//Press
Tv.settextcolor (0xff00cd66);
} else if (event.getaction () = = motionevent.action_up) {//talk about
Tv.settextcolor (0xFFFFFFFF);
Mdatas.remove (mposition);
Notifydatasetchanged ();
Toast.maketext (mcontext, "delete succeeded", Show_time). SHOW ();

if (Popupwindow! = null) {
Popupwindow.dismiss ();
}
}
}
return true;
}


}



Finally, we add a listener to the GetView.

ViewHolder.content.setOnLongClickListener (New Onlongclicklistener () {


@Override
public boolean Onlongclick (View v) {
TODO auto-generated Method Stub
Showpop (v);
Copytv.setontouchlistener (New Tvontouch (Mcontext, position));
Deletetv.setontouchlistener (New Tvontouch (Mcontext, position));
return false;
}
});

The solution to the focus of Android's ListView and TextView

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.