내 활동에 목록보기를 추가하려고합니다. 다음과 같은 상황이 발생합니다. 사용자가 단추를 클릭하면 asyncTask를 사용하여 인터넷에서 데이터를 가져옵니다. 그러면 해당 데이터가 목록보기에 추가됩니다. 데이터는 테이블에서 온라인으로 나오므로 테이블에 10 개의 행이 있고 Listview에 10 개의 값이 있어야합니다.ListView에 추가
하지만 몇 가지 문제가 있습니다. 먼저 listview를 기존 레이아웃에 추가하고 즉시 업데이트 할 수 있습니까?
목록보기는 setContentView() 메서드를 사용할 수없고 setListAdapter를 사용해야한다는 것을 의미합니까?
- 이미 배치 된 두 개의 버튼이있는 레이아웃이있는 경우 목록보기를 아래에 추가 할 수 있으며 setContentView() 메소드를 사용하여 구현할 수 있습니까?
감사
편집
업데이트 코드 - 작품 :
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.new_sightings);
ListView list = getListView();
list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values));
list.setTextFilterEnabled(true);
}
XML 레이아웃
?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation = "vertical">
<TableLayout
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
>
<TableRow
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:layout_weight = "1"
>
<TextView
android:id = "@+id/txtTitle"
android:layout_width = "wrap_content"
android:layout_height = "fill_parent"
android:layout_weight = "1"
android:gravity = "center"
android:text = "ISS Predictions"
android:textStyle="bold"
android:textColor = "#FFFFFF"
/>
<Button
android:id="@+id/reloadTen"
android:layout_height="wrap_content"
android:layout_width ="fill_parent"
android:layout_gravity = "right"
android:layout_weight = "1"
android:text = "Reload"
android:textColor = "#FFFFFF"
android:textStyle = "bold"
android:background = "#000000"
/>
</TableRow>
</TableLayout>
<ListView
android:id = "@+id/android:list"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:textSize = "15dp"
android:textStyle = "bold"
/>
</LinearLayout>
나는 위의 두 대답 모두를 좋아하지만 하나를 골라야하므로이 코드를 가져옵니다. 고마워, 또 다른 사람이 같은 문제를 일으키는 경우에 대비하여 코드를 추가했습니다. – Katana24