开发者

How can i attach an listener to listview?

I have a ListView with a custom layout for each row having one TextView and three EditText. When I am clicking on individual row in ListView one activity is started and that takes you to another page.

I wrote some code but its not working. The code is shown below.

In adapter class getView() method i have place the below code

   convertView = mInf开发者_如何学运维later.inflate(R.layout.editcategorylist, null);
   convertView.setClickable(true); 
   convertView.setOnClickListener(clickListener);

and I declare the click listener in your ListActivity as follows

   lv=getListView();  
   myClickListener = new OnClickListener(){
       public void onClick(View v) {
           Intent intent = new Intent(CategoryList.this,AddSubCategoryList.class);
           startActivity(intent);    
       }
   };

Thank you.


Use something like this

lv.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() 
{
 public void onItemSelected(AdapterView parentView, View childView, int position, long id) 
 {
    //Here write your code for starting the new activity on selection of list item
 }
 public void onNothingSelected(AdapterView parentView) 
 {
 }
});


Please use setOnItemClickListener

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜