我已经设置onItemClicklistener
了我的自定义列表视图但onItemClicklistener
没有工作我也尝试了自定义列表视图的设置focusable="false"
和focusableInTouchMode="false"
控件。我也看到了相关的问题,但没有帮助。
请帮忙
public class SwipingActivity extends Activity {
public OnTouchListener gestureListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView lv = (ListView)findViewById(R.id.mylistview);
gestureListener = new View.OnTouchListener() {
private int padding = 0;
private int initialx = 0;
private int currentx = 0;
private ViewHolder viewHolder;
public boolean onTouch(View v, MotionEvent event) {
if ( event.getAction() == MotionEvent.ACTION_DOWN)
{
padding = 0;
initialx = (int) event.getX();
currentx = (int) event.getX();
viewHolder = ((ViewHolder) v.getTag());
}
if ( event.getAction() == MotionEvent.ACTION_MOVE)
{
currentx = (int) event.getX();
padding = currentx - initialx;
}
if ( event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL)
{
padding = 0;
initialx = 0;
currentx = 0;
}
if(viewHolder != null)
{
if(padding == 0)
{
v.setBackgroundColor(0xFF000000 );
Toast.makeText(getApplicationContext(), viewHolder.text.getText().toString(), 5);
}
if(padding > 75)
{
viewHolder.setRunning(true,viewHolder);
}
if(padding < -75)
{
viewHolder.setRunning(false,viewHolder);
}
v.setBackgroundColor(viewHolder.getColor());
v.setPadding(padding, 0,0, 0);
}
return true;
}
};
ModelArrayAdapter adapter = new ModelArrayAdapter(this, getData(),gestureListener);
lv.setAdapter(adapter);
lv.setFocusable(true);
lv.setOnTouchListener(gestureListener);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
TextView txt = (TextView) arg1.findViewById(R.id.TextView01);
Toast.makeText(getApplicationContext(), txt.getText().toString(), 5);
}
});
}
@sam 我已经添加了代码。请检查它....