我制作了一个自定义列表视图,其中每行有两个textview和一个搜索栏。我想最初只显示一个文本视图,当用户点击某个项目时,列表应该展开到全屏并显示textviews和seekbar。
这是我迄今取得的成就:
public class ExpandableListActivity extends ListActivity
{
Context context;
private TextView mTitle;
private TextView mDialogue;
private SeekBar seekbar;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
context = this;
// Use our own list adapter
setListAdapter(new ListAdapter(this));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
}
private class ListAdapter extends BaseAdapter {
public ListAdapter(Context context)
{
mContext = context;
}
public int getCount() {
return mTitles.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
View rowView = inflater.inflate(R.layout.listlayout, null, true);
mTitle = (TextView) rowView.findViewById(R.id.textView1);
mDialogue= (TextView) rowView.findViewById(R.id.textView2);
seekbar = (SeekBar)rowView.findViewById(R.id.seekBar1);
mTitle.setText(mTitles[position]);
mDialogue.setText(mDialogues[position]);
return rowView;
}
private Context mContext;
String [] mTitles = getResources().getStringArray(R.array.state_name);
String [] mDialogues = getResources().getStringArray(R.array.capital_name);
}
}
答案 0 :(得分:0)
使用ExpandableListActivity或ExpandableListView。 http://techdroid.kbeanie.com/2010/09/expandablelistview-on-android.html
答案 1 :(得分:0)
看起来您需要查看ListView tutorial。您的getView()
可能有效,但在使用现有API方面效果不佳。然后使用所需的行为实现onListItemClick(...)
。另外,正如Kumar Bibek所写,您可能需要查看ExpandableListView。