开发者

android: creating a textfield display on the same activity with a ListActivity

开发者 https://www.devze.com 2023-02-28 03:54 出处:网络
I have an activity that pulls a String Array from xml and displays a ListActivity (the class extends ListActivity) and I\'d like to know if it is possible to also display a textfield or textView below

I have an activity that pulls a String Array from xml and displays a ListActivity (the class extends ListActivity) and I'd like to know if it is possible to also display a textfield or textView below the list?

If so, what method should I research to do this? Have code samples?

Thanks!

CODE:

public class txchl extends ListActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    //setContentView(R.layout.main);
    String[] rme开发者_StackOverflow社区nu = getResources().getStringArray(R.array.root_menu);
    if (rmenu != null) {
        setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, rmenu));
    }
    TextView tv = new TextView(this);
    tv.setText("Hello");
    setContentView(tv);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    //
    if (position == 4 || position == 5) {
        Intent myIntent = new Intent(v.getContext(), Activity2.class);
        myIntent.putExtra("com.activity.Key", position);
        startActivity(myIntent);
    } else {
        Intent myIntent = new Intent(v.getContext(), txchl_hb.class);
        myIntent.putExtra("com.activity.Key", position);
        //myIntent.putExtra("com.activity.Dir", directives[position]);
        startActivity(myIntent);
    }
}

}


What you want is a vertical LinearLayout that contains a ListView and a TextView

There is an example of what you want to achieve in the android reference:

ListActivity has a default layout that consists of a single, full-screen list in the center of the screen. However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). To do this, your own view MUST contain a ListView object with the id "@android:id/list" (or list if it's in code)

http://developer.android.com/reference/android/app/ListActivity.html

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:paddingLeft="8dp"
         android:paddingRight="8dp">

     <ListView android:id="@id/android:list"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:background="#00FF00"
               android:layout_weight="1"
               android:drawSelectorOnTop="false"/>

     <TextView android:id="@id/android:empty"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:background="#FF0000"
               android:text="No data"/>
 </LinearLayout>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号