【发布时间】:2014-06-26 17:12:16
【问题描述】:
我目前有一个程序可以在用户单击按钮时显示列表视图。这个视图占据了整个屏幕。我怎样才能(而不是必须按下按钮进入列表视图)将主屏幕分成两部分,一个是大列表视图,两个是几个按钮?
这就是我使用 listView 适配器的方式: 公共无效showPopUp(){ ListArrayAdapter 适配器 = new ListArrayAdapter(this, R.layout.list_view_row_item, foodList);
ListView listViewItems = new ListView(this);
listViewItems.setAdapter(adapter);
listViewItems.setOnItemClickListener(new OnListItemClick());
alertDialogStores = new AlertDialog.Builder(MainScreen.this)
.setView(listViewItems)
.setTitle("Food List")
.show();
}
这是适配器:
public class ListArrayAdapter extends ArrayAdapter<ListItem> {
Context mContext;
int layoutResourceId;
ListItem data[] = null;
private ProgressBar progressBar;
private int progressStatus = 0;
private TextView textView;
private Handler handler = new Handler();
ArrayList<ListItem> foodList = new ArrayList<>();
//public ArrayAdapterItem(Context mContext, int layoutResourceId, ListItem[] data) {
public ListArrayAdapter(Context mContext, int layoutResourceId, ArrayList<ListItem> foodList) {
super(mContext, layoutResourceId, foodList);
this.layoutResourceId = layoutResourceId;
this.mContext = mContext;
this.foodList = foodList;
//this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
/*
* The convertView argument is essentially a "ScrapView" as described is Lucas post
* http://lucasr.org/2012/04/05/performance-tips-for-androids-listview/
* It will have a non-null value when ListView is asking you recycle the row layout.
* So, when convertView is not null, you should simply update its contents instead of inflating a new row layout.
*/
if(convertView==null){
// inflate the layout
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
convertView = inflater.inflate(layoutResourceId, parent, false);
}
// object item based on the position
//ListItem ListItem = data[position];
// get the TextView and then set the text (item name) and tag (item ID) values
TextView textViewItem = (TextView) convertView.findViewById(R.id.itemName);
textViewItem.setText(foodList.get(position).getItemName());
textViewItem.setTag(foodList.get(position).getItemIdInt());
progressBar = (ProgressBar) convertView.findViewById(R.id.progressBar1);
return convertView;
}
}
我也想知道当用户按住一个项目时是否有可能出现一条消息(并在他们放手后让它徘徊一点)。
【问题讨论】: