[英]Two clickable items in list view
我有一個Android Eclair(2.1)手機,我正在通過通話記錄功能和
我通過一個列表視圖,在觸摸左側時,我被重定向到另一個列表視圖,其中包含更詳細的呼叫記錄 ,在右側,我得到一個“呼叫”按鈕 ,
經過研究和瀏覽互聯網上的多個帖子我無法知道如何實現這一點,我想在我的應用程序中實現此功能。
這里的任何人都可以請我重新定向任何好的教程。
您可以在基本適配器中的getview方法中執行以下操作:
public View getView(final int position, View convertView, ViewGroup parent) {
DemoClass holder;
if (convertView == null) {
convertView = mInflater.inflate(
R.layout.layout_name, null);
holder = new DemoClass();
holder.mTxtVwNameTag = (TextView) convertView
.findViewById(R.id.TxtVwOptionName);
holder.mBtnApply = (Button) convertView.findViewById(R.id.BtnApply);// Here you can handle onclick events for list view items
holder.mBtnApply.setFocusable(false);
holder.mBtnApply.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mIntPos = position;
Log.d("++++++++" , "List item Position : " + mIntPos);
new ApplyOfferAsync().execute();
}
});
convertView.setTag(holder);
} else {
holder = (DemoClass) convertView.getTag();
}
try {
holder.mTxtVwNameTag.setText(mNameTags.get(position));
} catch (Exception e) {
e.printStackTrace();
}
return convertView;
}
你必須使用觸摸偵聽器或你的coustom布局。
wv.setOnTouchListener(new OnTouchListener()
{
public boolean onTouch(View arg0, MotionEvent arg1)
{
try
{
if(arg1.getAction()==MotionEvent.ACTION_DOWN)
{
x_down = (int) arg1.getX();
y_down = (int) arg1.getY();
Log.v("log", "x pos is "+x_down +"y pos is "+y_down);
return true;
}
else if(arg1.getAction()==MotionEvent.ACTION_UP)
{
x_up = (int) arg1.getX();
y_up = (int) arg1.getY();
Log.v("log", "x pos is "+x_up +"y pos is "+y_up);
if((x_down-x_up)>30)
{
//do stuf here
}
else if((x_up-x_down)>30)
{
//do stuf here
}
return false;
}
else
{
return false;
}
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.