问题
this is my code:
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:
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;
}
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.
How to click on a specific?
this is my list view table:
<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>
回答1:
For being able to move to other activity by clicking on certain View inside the row, you need to set OnClickListener to your view inside getView method.
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);
// ... here ->
TextView button = (TextView) vowView.findViewById(R.id.addBtn);
button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// open here other activity
}
});
// <- ....
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;
}
回答2:
Have a look at this blog, which is about clikable zones in listview items, this might be helpful.
来源:https://stackoverflow.com/questions/18571174/how-to-click-on-a-particular-column-in-a-list-view-android