我正在对多个相同的视图进行充气,并且还能够删除我膨胀的视图。
我目前遇到的问题是,我希望能够将一个项目添加到已经膨胀的视图中,该视图可能已经添加了一些视图。
当用户将房间1输入页面左上角的框中时(目前显示房间2),然后按+按钮,它将把它添加到已经存在的房间1列表如下。目前它只是将它添加到Room 2,这是动态创建的最新视图。
问题是一切都是动态创建的,我似乎无法获得视图的值。
以下是匹配“+”点击的代码段:
plus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
room = roomname.getText().toString();
if(roomList.isEmpty()) {
roomList.add(room);
LayoutInflater layoutInflaterroom = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addRoom = layoutInflaterroom.inflate(R.layout.newroom, null);
rLayout = (LinearLayout) addRoom.findViewById(R.id.room);
roomnametitle = (TextView) addRoom.findViewById(R.id.listroomname);
removeroom = (Button) addRoom.findViewById(R.id.removeRoom);
removeroom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((LinearLayout) addRoom.getParent()).removeView(addRoom);
roomnametitle.getText().toString();
roomList.remove(roomnametitle);
}
});
roomnametitle.setText(room);
mLayout.addView(addRoom);
LayoutInflater layoutInflateritem = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflateritem.inflate(R.layout.newitem, null);
quoteitem = (TextView) addView.findViewById(R.id.partName);
quoteitemquantity = (TextView) addView.findViewById(R.id.quantity);
quoteitemrrp = (TextView) addView.findViewById(R.id.rrp);
new Search().execute();
buttonRemove = (Button) addView.findViewById(R.id.remove);
buttonRemove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((LinearLayout) addView.getParent()).removeView(addView);
}
});
rLayout.addView(addView);
scroll.post(new Runnable() { public void run() { scroll.fullScroll(View.FOCUS_DOWN); } });
} else if (roomList.contains(room)) {
LayoutInflater layoutInflateritem = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflateritem.inflate(R.layout.newitem, null);
quoteitem = (TextView) addView.findViewById(R.id.partName);
quoteitemquantity = (TextView) addView.findViewById(R.id.quantity);
quoteitemrrp = (TextView) addView.findViewById(R.id.rrp);
new Search().execute();
buttonRemove = (Button) addView.findViewById(R.id.remove);
buttonRemove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((LinearLayout) addView.getParent()).removeView(addView);
}
});
rLayout.addView(addView);
scroll.post(new Runnable() { public void run() { scroll.fullScroll(View.FOCUS_DOWN); } });
} else {
roomList.add(room);
LayoutInflater layoutInflaterroom = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addRoom = layoutInflaterroom.inflate(R.layout.newroom, null);
rLayout = (LinearLayout) addRoom.findViewById(R.id.room);
roomnametitle = (TextView) addRoom.findViewById(R.id.listroomname);
removeroom = (Button) addRoom.findViewById(R.id.removeRoom);
removeroom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((LinearLayout) addRoom.getParent()).removeView(addRoom);
roomnametitle.getText().toString();
roomList.remove(roomnametitle);
}
});
roomnametitle.setText(room);
mLayout.addView(addRoom);
LayoutInflater layoutInflateritem = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflateritem.inflate(R.layout.newitem, null);
quoteitem = (TextView) addView.findViewById(R.id.partName);
quoteitemquantity = (TextView) addView.findViewById(R.id.quantity);
quoteitemrrp = (TextView) addView.findViewById(R.id.rrp);
new Search().execute();
buttonRemove = (Button) addView.findViewById(R.id.remove);
buttonRemove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((LinearLayout) addView.getParent()).removeView(addView);
}
});
rLayout.addView(addView);
scroll.post(new Runnable() { public void run() { scroll.fullScroll(View.FOCUS_DOWN); } });
}
你会在这段代码中看到我试图从roomList删除相应的房间,如果他们按下“删除房间”,但这似乎也没有计划。
我会接受任何建议/帮助。我试过谷歌搜索,但不知道具体谷歌。