ListView控件setOnItemClickListener不是在自定义列表视图中工作 [英] ListView setOnItemClickListener not working in custom list view

查看:205
本文介绍了ListView控件setOnItemClickListener不是在自定义列表视图中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文本视图,每行中的一个编辑文字,列表视图setOnItemClickListener()列表视图中是行不通的。

I have a list view with two text view and one edit text in each row , list view setOnItemClickListener() is not working.

在这里,我的Java code。

public class CreateChallan extends Activity {


ListView lstCreate;

String[] strmainItemCode;
String[] strItem;
String[] strQuantity;
Context context=this;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.createchallan);
    lstCreate= (ListView) findViewById(R.id.createlist);
    lstCreate.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);

    strmainItemCode= new String[]{"555551","255555","355555","455555","555555"};

    strItem =new String[]{"A","B","C","D","F"};

    strQuantity =new String[]{"100","200","30","400","500"};

    CreateAdapter adapter= new CreateAdapter(this, strmainItemCode, strItem, s trQuantity);

    lstCreate.setAdapter(adapter);

    lstCreate.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int position1, long id) {
            // TODO Auto-generated method stub

            Toast.makeText(context, "Position",   Toast.LENGTH_LONG).show();

        }
    });
}







// Create List Adapter

class CreateAdapter extends ArrayAdapter<String>
 {
    TextView txtItecode, txtItem;
    EditText editQuantity;
    String[] strItecode;
    String[] strItem;
    String[] strQuantity;
    Context context;

    CreateAdapter(Context context, String[] strItemcode, String[] strItem,  String[] strQauntity)
    {
           super(context,R.layout.create_list_item,R.id.txtItemcode,strItemcode);
        this.context= context;
        this.strItecode= strItemcode;
        this.strItem= strItem;
        this.strQuantity= strQauntity;
    }
     public View getView(int position, View convertView, ViewGroup parent) {
         LayoutInflater mInflater = (LayoutInflater)  context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
         View row;
         row=mInflater.inflate(R.layout.create_list_item, parent,false);

         txtItecode= (TextView) row.findViewById(R.id.txtItemcode);
         txtItem =(TextView) row.findViewById(R.id.txtItem);
         editQuantity = (EditText)  row.findViewById(R.id.editcreateQuantity);

         txtItecode.setText(strItecode[position]);
         txtItem.setText(strItem[position]);
        editQuantity.setText(strQuantity[position]);

         txtItecode.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(context, "click", Toast.LENGTH_LONG).show();
            }
        });

         return row;


     }
 }


}

在这里,我的名单XML code

 <ListView
    android:id="@+id/createlist"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   android:clickable="true"
    android:cacheColorHint="#00000000"
    android:divider="#adb8c2"
    android:dividerHeight="1dp"
    android:scrollingCache="false"
    android:smoothScrollbar="true" 
    android:focusable="false"
android:focusableInTouchMode="false"

   >

</ListView>

请推荐我,我怎么能解决这个问题。

Please Suggest me How i can fix this problem.

在此先感谢

推荐答案

设置这些特性

 android:focusable="false"
 android:focusableInTouchMode="false"

在您的 create_list_item xml文件的所有UI元素。

for your all UI elements in your create_list_item xml file.

同时删除从ListView控件的属性。

Also remove that properties from ListView.

所以,你的ListView将

So your ListView will be

 <ListView
   android:id="@+id/createlist"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:clickable="true"
   android:cacheColorHint="#00000000"
   android:divider="#adb8c2"
   android:dividerHeight="1dp"
   android:scrollingCache="false"
   android:smoothScrollbar="true">
 </ListView>

这篇关于ListView控件setOnItemClickListener不是在自定义列表视图中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆