첫 번째로, 안드로이드 코딩의 대다수에 대해 매우 확신하지 못하고 있습니다. 이것은 단지 두 번째 날이므로, 설명에서 실수를 저 지르십시오.스크롤링 작업에 SQLite 배열 적용?
SQLite를 통해 데이터베이스가 있고 현재 listView를 통해 데이터를 표시하고 있습니다. 현재, 그것은 데이터를 표시 잘 작동하고 스크롤하고 아무 문제도 그것을 클릭 할 수 있습니다. 그러나 Android Studio에서 찾을 수있는 '스크롤링 활동'템플릿에 내 데이터를 배치하고 싶습니다. Googling around에서 나는 activity가 사용하는 nestedScrollView에 listView를 배치 할 수 없다는 것을 이해합니다.
그러나 listView를 사용하지 않고 데이터베이스에서 내 데이터를 표시하는 방법은 확실하지 않습니다. 누군가 나 listView 뭔가 호환, 또는 그들을 결합하는 방법을 설명 해달라고 도와 주시겠습니까 (해키 메서드는 지금 괜찮아요!)
나는 아래에 필요한 코드를 모두 표시했습니다.
MainActivity.java :
mydb = new DBHelper(this);
ArrayList array_list = mydb.getAllCotacts();
ArrayAdapter arrayAdapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1, array_list);
obj = (ListView)findViewById(R.id.listView1);
TextView emptyText = (TextView)findViewById(android.R.id.empty);
obj.setEmptyView(emptyText);
obj.setAdapter(arrayAdapter);
obj.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
// TODO Auto-generated method stub
int id_To_Search = arg2 + 1;
Bundle dataBundle = new Bundle();
dataBundle.putInt("id", id_To_Search);
Intent intent = new Intent(getApplicationContext(),DisplayContact.class);
intent.putExtras(dataBundle);
startActivity(intent);
}
});
content_scrolling.xml : 내가 말하는대로 실수에 대한
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="uk.ac.tees.q5065885.diary.ScrollingActivity"
tools:showIn="@layout/activity_scrolling">
<android.support.v7.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>
</android.support.v7.widget.LinearLayoutCompat>
<TextView
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/emptyText"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</android.support.v4.widget.NestedScrollView>
사과는,이 나의 두 번째 날입니다; 나는 가능한 한 빨리 배우고있다!
(당신이 :) 좋아하면 그것을 사용자 정의, 아주 예쁜되지 않음)
XML : 당신은 이런 식으로 뭔가를 시도 할 수 있습니다. 이것이 스크롤링에 필요한 전부입니다. 이 코드의 문제점은 무엇입니까? –
참고 : ListView가있는 SQLite 데이터베이스를 사용하는 경우 ArrayAdapter보다 CursorAdapter가 좋습니다. –