gpt4 book ai didi

android - 如何在android中为Listview的项目点击应用条件

转载 作者:太空狗 更新时间:2023-10-29 15:01:53 26 4
gpt4 key购买 nike

private void showPopup(final Activity context, Point p) {
int popupWidth = 800;
int popupHeight = 1100;

// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout) context
.findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.notifcationpopup_layout,
viewGroup);
popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(popupWidth);
popup.setHeight(popupHeight);
popup.setFocusable(true);

// Some offset to align the popup a bit to the right, and a bit down,
// relative to button's position.
int OFFSET_X = 100;
int OFFSET_Y = 40;

// Clear the default translucent background
popup.setBackgroundDrawable(new BitmapDrawable());

// Displaying the popup at the specified location, + offsets.
popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y
+ OFFSET_Y);

rowItems = new ArrayList<RowItem>();
// for (int i = 0; i < titles.length; i++) {
// RowItem item = new RowItem(titles[i], descriptions[i]);
// rowItems.add(item);
// }
dbManager1 = new DataBaseManager(context);
notifies = dbManager1.getNotificationList();
System.out.println("today " + notifies.size());
for (int i = 0; i < notifies.size(); i++) {
System.out
.println("Valueeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee:"
+ notifies.get(i).getNotificationDescrpiton()
+ "\n"
+ notifies.get(i).getNotificationServerId()
+ "\n" + notifies.get(i).getNotificationDatetime());

}
listView = (ListView) layout.findViewById(R.id.listView1);
Notifcationadapter adapter = new Notifcationadapter(this, notifies);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);

}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub

String notifcationtype = notifies.get(position).getNotificationType();
String nOtifcationMessge = notifies.get(position)
.getNotificationDescrpiton();
String notifcationdatetime = notifies.get(position)
.getNotificationDatetime();

String NotifcationSenderid = notifies.get(position)
.getNotificationSenderID();
String NotifcationRecciverid = notifies.get(position)
.getNotificationRecieverID();

final int positionRow = listView.getPositionForView((View) view
.getParent());

String Latreccvier = "";
String Lonreccvier = "";
Cursor cursor = dbManager1.fetchContactInfo(NotifcationRecciverid);
if (cursor != null && cursor.moveToFirst()) {

Latreccvier = cursor.getString(cursor

.getColumnIndex(DataProviderConstants.CONTACT_LAT_COLUMN));

Lonreccvier = cursor.getString(cursor

.getColumnIndex(DataProviderConstants.CONTACT_LON_COLUMN));

cursor.close();

}

Log.e("Reccvierid", NotifcationRecciverid);
Log.e("Reccvierid", Latreccvier);
Log.e("Reccvierid", Lonreccvier);

// Intent i = null;
if (notifcationtype.equals("1")) {
// i = new Intent(context, PostActivity.class);

Intent i = new Intent(this, RoutePathActivity.class);
i.putExtra("lat", Latreccvier);
i.putExtra("lon", Lonreccvier);
startActivity(i);
Toast.makeText(this, "Request", 1000).show();

} else if (notifcationtype.equals("2")) {

displayView(0);

// ((FragHome) fragment).showMap();

popup.dismiss();

Toast.makeText(this, "Post", 1000).show();

}

}

这是我的弹出窗口的 HOmeActivity 代码。

public class Notifcationadapter extends BaseAdapter {
private static ArrayList<Notify> values;
Context context;
String senderid;
String imagepath;

// List<RowItem> rowItems;
ViewHolder holder = null;

LinearLayout linear2;

DataBaseManager dbManager = new DataBaseManager(context);
ArrayList<Notify> notifies;

public Notifcationadapter(Context context, ArrayList<Notify> notifies) {
super();
this.context = context;
this.notifies = notifies;

}

/* private view holder class */
private class ViewHolder {

TextView txtTitle;
TextView txtDesc;
ImageView yesimage;

ImageView noimage;
TextView revresetime;

TextView rejected;
ImageView notificationuserimage;
LinearLayout linear2;

}

public View getView(int position, View convertView, ViewGroup parent) {

LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.notifcationlistitem, null);
holder = new ViewHolder();
holder.linear2 = (LinearLayout) convertView
.findViewById(R.id.linear2);
holder.txtDesc = (TextView) convertView.findViewById(R.id.desc);

holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
holder.yesimage = (ImageView) convertView
.findViewById(R.id.imageView1);
holder.noimage = (ImageView) convertView
.findViewById(R.id.imageView2);
holder.revresetime = (TextView) convertView
.findViewById(R.id.revresetime);
holder.rejected = (TextView) convertView
.findViewById(R.id.rejectedrequest);
holder.notificationuserimage = (ImageView) convertView
.findViewById(R.id.notificationuserimage);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}

// holder.txtTitle.setText("Title");
String statustype = notifies.get(position).getNotificationType();

if (statustype.equals("1")) {

holder.txtDesc.setText(notifies.get(position)
.getNotificationDescrpiton());

holder.revresetime.setText(Functions
.setLastSeenNotifcationTime(notifies.get(position)
.getNotificationDatetime()));
holder.txtTitle.setText("Request For travelling");

senderid = notifies.get(position).getNotificationSenderID();
imagepath = "http://api.lociiapp.com/TransientStorage/"

+ senderid + ".jpg";
AQuery aq = new AQuery(context);

aq.id(holder.notificationuserimage).image(imagepath);

holder.yesimage.setVisibility(View.VISIBLE);
holder.noimage.setVisibility(View.VISIBLE);

holder.yesimage.setTag(convertView);
holder.yesimage.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
View parentView = (View) arg0.getTag();
View view = parentView.findViewById(R.id.imageView1);
view.setVisibility(View.GONE);
view = parentView.findViewById(R.id.imageView2);
view.setVisibility(View.GONE);
view = parentView.findViewById(R.id.linear2);
view.setVisibility(View.INVISIBLE);
view = parentView.findViewById(R.id.runnimage);
view.setVisibility(View.INVISIBLE);
Toast.makeText(context, "Yes", 10000).show();

}
});
holder.noimage.setTag(convertView);
holder.noimage.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
View parentView = (View) v.getTag();
View view = parentView.findViewById(R.id.imageView1);
view.setVisibility(View.GONE);
view = parentView.findViewById(R.id.imageView2);
view.setVisibility(View.GONE);
view = parentView.findViewById(R.id.rejectedrequest);
view.setVisibility(View.VISIBLE);
Toast.makeText(context, "NO", 10000).show();
// holder.linear2.setVisibility(View.INVISIBLE);
holder.yesimage.setVisibility(View.GONE);
holder.noimage.setVisibility(View.GONE);
holder.rejected.setVisibility(View.VISIBLE);
}
});

}

else {

holder.txtDesc.setText(notifies.get(position)
.getNotificationDescrpiton());
holder.txtTitle.setText("Post");
holder.revresetime.setText(Functions
.setLastSeenNotifcationTime(notifies.get(position)
.getNotificationDatetime()));

senderid = notifies.get(position).getNotificationSenderID();
imagepath = "http://api.lociiapp.com/TransientStorage/"

+ senderid + ".jpg";
AQuery aq = new AQuery(context);
holder.yesimage.setVisibility(View.GONE);
holder.noimage.setVisibility(View.GONE);
}

if (position % 2 == 0) {

convertView.setBackgroundColor(Color.parseColor("#ffffff"));
}

else {
convertView.setBackgroundColor(Color.parseColor("#f5f6f1"));

}

return convertView;
}

@Override
public int getCount() {
return notifies.size();
}

@Override
public Object getItem(int position) {
return notifies.get(position).getNotificationType();
}

@Override
public long getItemId(int position) {
return position;
}

}

这是我的 ListView 适配器类,当打印 ListView 时,每个 ListView 项中有一个按钮 YES 或 No。我想当我们点击是按钮时,只有 itemclik 应该工作我的意思是点击一个项目我应该进入另一个 Activity 如果我们点击否按钮那么它不应该工作项目点击意味着在列表项目上点击我不应该去另一个 Activity

下面是 ListView 屏幕:enter image description here

最佳答案

请检查我是否已编辑您的代码。 yesimage 是你的勾选图像按钮。在您的 Notifcationadapter 类中更新以下代码。

     holder.yesimage.setOnClickListener(new OnItemClickListener( position ));

private class OnItemClickListener implements OnClickListener{
private int mPosition;
OnItemClickListener(int position){
mPosition = position;
}
@Override
public void onClick(View arg0) {
context.onItemtickClick(mPosition);
}
}

在您的主页 Activity 中,为 onItemtickClick 添加以下代码。

      public void onItemtickClick(int mPosition) {
// TODO Auto-generated method stub
Intent i = new Intent(HomeActivity.this,RoutePathActivity.class);
i.putExtra("lat", Latreccvier);
i.putExtra("lon", Lonreccvier);
startActivity(i);
}

关于android - 如何在android中为Listview的项目点击应用条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25718851/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com