まず、Androidのコーディングの大部分は非常にわかりませんが、これは私の2日目のことですので、私の説明で間違いをお許しください!スクロールアクティビティにSQLite配列を適用しますか?
私はSQLite経由でデータベースを取得していますが、現在はlistView経由でデータを表示しています。現在、それはデータを表示するうまく動作し、私はそれをスクロールしてクリックすることができます。しかし、私はAndroid Studioで見つけることができる "スクロールアクティビティ"テンプレート内に自分のデータを配置したいと思います。 Googlingから、私はあなたがlistViewをnestedScrollViewに置くことができないことを幾分理解しています。これはアクティビティが使用するものです。
ただし、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>
謝罪が、これは私の二日目です。私はできるだけ早く学びます!
あなたは、アダプタとリストビューを持っている:あなたはこのような何かを試すことができます。それがスクロールに必要なすべてです。このコードの問題は何ですか? –
注:ListViewでSQLiteデータベースを使用している場合は、ArrayAdapterよりCursorAdapterが優先されます。 –