-2

在我的 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>      
4

1 回答 1

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

        }
    });

}
于 2012-12-03T12:23:02.500 回答