且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

列表视图中添加微调每一行?

更新时间:2023-12-04 10:27:28

下面是code在飞旋的列表视图顶部的膨胀:

 的ListView =(ListView控件)findViewById(R.id.list);        LayoutInflater吹气= LayoutInflater.from(本);
        查看mTop = inflater.inflate(R.layout.spin,NULL);
        authorityView.addHeaderView(mTop);

R.layout.spin是只包含微调的布局。
而列表里面,你必须只充气TextView的。如您在mylist.xml正在做的,
只是从中取出微调,并提出了微调seprate XML。

所以微调是一次,在布局(ListView控件)的顶部。

I am facing problem while putting Spinner in layout. My acctual requirement is to place Spinner once, at the top of layout.

This output I am getting:

I have Relative layout

   <Spinner
       android:id="@+id/spinner1"
        android:layout_width="fill_parent"
   android:layout_height="wrap_content" 
   android:entries="@array/string_array"
       android:prompt="@string/spinner_msg"
     />
     <TextView xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/notesTextView" 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content" 
   android:textColor="@android:color/white"
   android:minHeight="?android:attr/listPreferredItemHeight"
   android:gravity="center_vertical"
   android:textAppearance="?android:attr/textAppearanceMedium"
</TextView>`

MyActivity class is extended by ListActivity here's onCreate method

   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

     listView=getListView();
     listView.setOnItemClickListener(listener);
     spinner1=(Spinner)findViewById(R.id.spinner1);
     getDetailsCursor();
    String[] from = new String[] {"db_column"};
    int[] to = new int[] { R.id.notesTextView};
            curAdapter=new SimpleCursorAdapter(MyActivity.this, R.layout.mylist, null, from, to);
            setListAdapter(curAdapter);
        registerForContextMenu(listView);
    }`

Here is the code in which spinner inflates on the top of listview :

listView= (ListView) findViewById(R.id.list);

        LayoutInflater inflater = LayoutInflater.from(this);
        View mTop = inflater.inflate(R.layout.spin, null);
        authorityView.addHeaderView(mTop);

R.layout.spin is that layout which contains only spinner. And inside the List you have to inflate textView only. as you are doing in mylist.xml , just remove spinner from it and made seprate xml for spinner.

so spinner is once, at the top of layout (ListView).