我做了一个自定义的ListView我的Android应用程序,我有创造的该项目的不同部分单独onClickListeners一个问题。 我的项目有一个图片和文本。我要的是启动不同的活动,这取决于那些已经被点击了。
I have made a custom listView for my android app, and I have a problem creating separate onClickListeners for separate parts of the item. My item has a picture and a text. What I want is to start different activities depending on which of those has been clicked.
这的onClick()方法768,16开始活动,这使得它不可能确定在getView()我的DataBinder类的方法。 (DataBinder的infalates我的ListView自定义布局)
That onClick() method shoud start an activity which makes it impossible to define in getView() method of my DataBinder class. (DataBinder infalates my listView with custom layout)
任何帮助吗?
感谢您!
在自定义的 ListAdapter的
getView
方法,你应该添加 onClickListeners
来要采取行动,点击不同的子视图。
In your custom ListAdapter's
getView
method you should add onClickListeners
to the different sub-views you want to act to clicks.
就如何贯彻落实 getView
方法的一个例子:
An example on how to implement the getView
method:
class CustomListAdapter extends ArrayAdapter<String> implements OnClickListener {
public CustomListAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
TextView tv = (TextView) v.findViewById(R.id.textView1);
tv.setOnClickListener(this);
ImageView iv = (ImageView) v.findViewById(R.id.imageView1);
iv.setOnClickListener(this);
return super.getView(position, convertView, parent);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.textView1:
// Do stuff accordingly...
break;
case R.id.imageView1:
// Do stuff when imageView1 is clicked...
default:
break;
}
}
}
上一篇:使用CLR的UDT的SQL Server存储过程的参数存储过程、参数、UDT、CLR
下一篇:在HTML5应用程序缓存不中的Android PhoneGap的应用程序中使用应用程序、缓存、PhoneGap、oid