2011-04-21 4 views
0

XML에서 String Array를 가져 와서 ListActivity (클래스가 ListActivity를 확장 함)를 표시하는 액티비티가 있으며 가능한지 알고 싶습니다. 목록 아래에 텍스트 필드 또는 텍스트 뷰를 표시 하시겠습니까?android : ListActivity와 동일한 액티비티에 텍스트 필드를 표시합니다.

그렇다면 어떤 방법으로 조사해야합니까? 코드 샘플이 있습니까?

감사합니다.

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[] rmenu = 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); 
    } 
} 

}

답변

0

당신이 원하는 것은 당신이 안드로이드 기준에 달성하고자하는 내용의 예가있는 ListViewTextView

를 포함하는 수직 LinearLayout입니다 :

ListActivity에는 결함이 있습니다. t 레이아웃은 화면 중앙에 전체 화면으로 구성된 단일 목록으로 구성됩니다. 그러나 원하는 경우 onCreate()에서 setContentView()를 사용하여 자체 레이아웃을 설정하여 화면 레이아웃을 사용자 정의 할 수 있습니다. 이렇게하려면 ID로리스트 뷰 객체를 포함해야 자신의 견해는 "@android : ID /리스트"나는 두 객체에 나열된 한

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

(또는 목록을이 코드의 경우) 내 layout.xml 및 ListActivity를 사용하고 setContentView를 호출하지만 목록 만 볼 수 있습니다. 나는 OP에 코드를 추가 할 것이다. – bzo311

+0

위 코드는 ListView가 비어있는 경우에만 TextView를 표시합니다. 그것이 우리가 여기서 찾고있는 것인지 확실하지 않습니다. TextView의 android : id를 "@ id/android : empty"가 아닌 다른 것으로 변경해보십시오. – BigFwoosh

+0

ID를 편집 한 후 텍스트가 표시됩니다. 이제는 디스플레이 위치 및 서식 지정에 대해 염려 할 필요가 있습니다. 감사! – bzo311

관련 문제