本文介绍了如何在列表视图Android中单击特定列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
adapter= new EditAdapter(getApplicationContext(),sectionTopic);
setListAdapter(adapter);
ListView li = this.getListView();
li.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View myView, int position,
long arg3) {
TableLayout view = (TableLayout) myView ;
TextView name = (TextView) view.findViewById(R.id.name);
itemName = name.getText().toString();
Intent intent= new Intent(EditActivity.this, SectionDetailsActivity.class);
intent.putExtra("title", itemName);
startActivityForResult(intent,1);
}
});
EditAdapter:
EditAdapter:
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View vowView = inflater.inflate(R.layout.activity_edit, parent, false);
if (position%2==1){
vowView.setBackgroundColor(Color.rgb(170, 218, 203));
}
else{
vowView.setBackgroundColor(Color.rgb(147, 213, 212));
}
TextView name = (TextView) vowView.findViewById(R.id.name);
TextView budget = (TextView) vowView.findViewById(R.id.budget);
TextView expense = (TextView) vowView.findViewById(R.id.expense);
ImageView pic = (ImageView) vowView.findViewById(R.id.pic);
budget.setText(String.format("%.2f",arrayList.get(position).getBudget()));
name.setText(arrayList.get(position).getName());
expense.setText(String.format("%.2f",arrayList.get(position).getMaking()));
AsyncDownloadImage image = new AsyncDownloadImage(pic);
image.execute(arrayList.get(position).getPic());
return vowView;
}
我有一个tableRow的ListView,当您单击一行时,您将移至另一个屏幕.除此以外,我还希望当我按某个列(在文本视图"addBtn"上)时,它将移动到另一个屏幕.
I have a ListView of a tableRow, that when you click on a row you move to another screen.I want that in addition to that, when I press on a certain column (on the text view- "addBtn") it will move to a different screen.
如何单击特定的内容?
这是我的列表视图表:
<TableRow
android:id="@+id/table"
android:baselineAligned="false"
android:background="#e0eee0" >
<TextView
android:id="@+id/addBtn"
android:layout_width="30dp"
android:layout_height="40dp"
android:layout_margin="0.5dp"
android:background="@drawable/plus"
android:gravity="center"
android:lines="2"
android:textColor="@color/Black"
/>
<TextView
android:layout_width="80dp"
android:layout_height="40dp"
android:id="@+id/expense"
android:layout_margin="0.5dp"
android:background="#e6e6fa"
android:gravity="center"
android:text="900"
android:textColor="@color/Black"
android:lines="2"
/>
<TextView
android:layout_width="80dp"
android:layout_height="40dp"
android:id="@+id/budget"
android:layout_margin="0.5dp"
android:background="#ffe4e1"
android:gravity="center"
android:text="1000"
android:lines="2"
android:textColor="@color/Black" />
<TextView
android:layout_width="80dp"
android:layout_height="40dp"
android:id="@+id/name"
android:layout_margin="0.5dp"
android:background="#e0eee0"
android:gravity="center"
android:text="מזון"
android:textColor="@color/Black"
android:lines="2" />
</TableRow>
推荐答案
看看这个博客,它与列表视图项中的易变区域有关,这可能会有所帮助.
Have a look at this blog, which is about clikable zones in listview items, this might be helpful.
这篇关于如何在列表视图Android中单击特定列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!