在我的Android应用程序中,当我单击Textview时,我想显示项目列表,它显示项目列表,我可以添加和删除该列表中的项目。我怎么能通过java代码来做到这一点 请指导。我将非常感谢你
我的代码是:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cus_name"
android:gravity="center"
android:clickable="true"
android:focusable="true"
android:onClick="onClick"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/cus_name_txta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/contact_no"
android:clickable="true"
android:focusable="true"
android:onClick="onClick"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/contact_no_txta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ticket_no"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/ticket_no_txta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<requestFocus />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:text="@string/task_detail"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/task_detail_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"/>
</LinearLayout>
答案 0 :(得分:0)
如果我理解正确,我会建议扩展Dialog
,以便在用户点击TextView
时弹出自定义对话框(包含在Imran Khan的回答中)。此对话框将包含ListView
以及处理列表所需的任何其他内容。我之前用过的这种方法的例子:
public class LogOverlay extends Dialog{
private Server mItem;
private boolean end=false;
private int mLimitHigh = 15;
private int mLimitLow = 0;
private ListView mListView;
private LogListAdapter mAdapter;
private ArrayList<LogUnit> mLog = new ArrayList<LogUnit>();
private boolean mScroll;
private Context context;
ProgressDialog pd;
public LogOverlay(Context context,Session session,Server server) {
super(context);
this.setContentView(R.layout.overlay_logs);
mListView=(ListView) this.findViewById(R.id.log_list);
mAdapter = new LogListAdapter(context, new ArrayList<LogUnit>(), new String[] {});
mListView.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
mListView.setDividerHeight(1);
mListView.setAdapter(mAdapter);
mListView.setOnScrollListener(new OnScrollListener() {
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
....
}
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
});
}