Hi
I am struggling to get my onItemLongClick Listener to be used with the simple cursor adapter getView. The onItemClick Listener which is also part of the app does interact with the getView but the LongClick does not
My Activity is a ListActivity :
I get the ListView as follows :
The long click is set to this listview as follows :
I use the booleans as a last resort thinking this would help when it reaches the getView which looks as follows :
My goal here is trying to highlight the bespoke row (made up of a linearlayout and several tables) when a long press occurs. I can get this to happen if the code in the getView sits in the onItemLongClick method but then the row selected stays selected if another is then chosen.
Also tried the suggestions from this post but keeping with the idea of using the onitemlonglick :
android - Items in ListView not long clickable after setting click listener in getView() - Stack Overflow
Please help
Thanks
TimCS
I am struggling to get my onItemLongClick Listener to be used with the simple cursor adapter getView. The onItemClick Listener which is also part of the app does interact with the getView but the LongClick does not
My Activity is a ListActivity :
Code:
public class MainActivity extends ListActivity
I get the ListView as follows :
Code:
final ListView datalist = getListView();
The long click is set to this listview as follows :
Code:
datalist.setLongClickable(true);
datalist.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
isclick = false;
islongclick = true;
return false;
}});
Code:
public View getView(int position,View convertView, ViewGroup parent) {
//Toast.makeText(getApplicationContext(), "Long Cick Reached Get View Method.... ", Toast.LENGTH_LONG).show();
View row = super.getView(position, convertView, parent);
//View row = convertView;
if (row == null) {
LayoutInflater grow;
grow = LayoutInflater.from(getBaseContext());
row = grow.inflate(R.layout.viewdata, null);
row.setLongClickable(true);
((TableLayout)row.findViewById(R.id.Table1)).setLongClickable(true);
((TableLayout)row.findViewById(R.id.Table2)).setLongClickable(true);
((TableLayout)row.findViewById(R.id.Table3)).setLongClickable(true);
}
if (islongclick) {
Toast.makeText(getApplicationContext(), "Long Cick Reached Get View Method.... ", Toast.LENGTH_LONG).show();
if (!longrowclick.equals(-1)) {
Toast.makeText(getApplicationContext(), "Long Cick Row - moving to previous row..... ", Toast.LENGTH_LONG).show();
// datalist.smoothScrollToPosition(longrowclick);
mC.moveToPosition(longrowclick);
((TableLayout)row.findViewById(R.id.Table1)).setBackgroundColor(Color.BLACK);
((TableLayout)row.findViewById(R.id.Table2)).setBackgroundColor(Color.BLACK);
((TableLayout)row.findViewById(R.id.Table3)).setBackgroundColor(Color.BLACK);
}
mC.moveToPosition(position);
if (mC.getPosition()==position ) {
((TableLayout)row.findViewById(R.id.Table1)).setBackgroundResource(R.drawable.darkslateblue);
((TableLayout)row.findViewById(R.id.Table2)).setBackgroundResource(R.drawable.darkslateblue);
((TableLayout)row.findViewById(R.id.Table3)).setBackgroundResource(R.drawable.darkslateblue);
}
longrowclick = position;
}
return row;
}
My goal here is trying to highlight the bespoke row (made up of a linearlayout and several tables) when a long press occurs. I can get this to happen if the code in the getView sits in the onItemLongClick method but then the row selected stays selected if another is then chosen.
Also tried the suggestions from this post but keeping with the idea of using the onitemlonglick :
android - Items in ListView not long clickable after setting click listener in getView() - Stack Overflow
Please help
Thanks
TimCS
addingLeft="10dp"