- アップデート、ドキュメントにより見た後、私はあなたがまだArrayAdapterを使用することができると思う -
ですから、listviewのドキュメントを見ればあなたが
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="countries_array">
<item>Bahrain</item>
<item>Bangladesh</item>
<item>Barbados</item>
<item>Belarus</item>
<item>Belgium</item>
<item>Belize</item>
<item>Benin</item>
</string-array>
</resources>
を参照し、使用それらをロードするために:
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, countries));
ここで問題となるのは、リストの最後に到達するタイミングと、さらにデータをロードする方法UIをブロックしません。
はこのように、自分自身に頭痛を大幅に節約するために、私はCommonsware Endless Adapter を使用することをお勧めします。このようにそれを行う: Android Endless List
:
import android.app.ListActivity;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import com.commonsware.cwac.endless.EndlessAdapter;
import java.util.ArrayList;
public class YourListActivity extends ListActivity {
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.main);
String[] countries = getResources().getStringArray(R.array.countries_array);
setListAdapter(new YourAdapter(countries));
}
class YourAdapter extends EndlessAdapter {
public YourAdapter(String[] list) {
super(new ArrayAdapter<String>(YourAdapter.this,
R.layout.row,
android.R.id.text1,
list));
}
@Override
protected View getPendingView(ViewGroup parent) {
View row=getLayoutInflater().inflate(R.layout.row, null);
return row.findViewById(android.R.id.text1);
}
@Override
protected boolean cacheInBackground() {
SystemClock.sleep(10000); // pretend to do work
//put logic here to fetch the data
//this happens in the background so you can't do anything with the UI
//return whether or not you have more data, true if you do false otherwise.
boolean haveMoreData = true;//this up to you to figure out
return haveMoreData;
}
@Override
protected void appendCachedData() {
//here is where you do the work to actually add the data obtained in cacheInBackground to the ArrayAdapter
ArrayAdapter<String> a=(ArrayAdapter<String>)getWrappedAdapter();
for (int i=0;i<25;i++) {
a.add(a.getCount());
}
}
}
}
}
ここでは、ここにあなた自身に似ています別の質問です - 更新:アダプタに複数の文字列配列を追加する方法 - これを行うには複数の方法がありますが、最も簡単な方法はおそらくアダプタの追加メソッドを使用することです。
これを見て:http://developer.android.com/reference/android/widget/ArrayAdapter.html そしてメソッドaddを見てください。 は現在、あなたは、変数の名前のアダプタがあります。あなたはそのアダプタにデータを追加したいときはいつでも
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, get_msgList);
を呼び出すだけ:
adapter.add("Some new data");
を
ですから、データの別のString []型の配列を持っていたし、あなたが望んでいた場合現在のアダプタにそのすべてを追加するために、ちょうど使用:
String[] someNewData = getStringArray();//no idea how you are getting the array, this is just an example
for (String s : someNewData) {
adapter.add(s);
}
を、新しいデータを追加した後、あなたはadapter.notifyDataSetChangedを呼び出す必要があるかもしれませんが、私はSじゃありませんure(それはあなたのために起こるかもしれない)..私はそれを最初に試してみて、すべてが期待どおりに働いているかどうか、それを加えないかどうかを見ます。
アダプター変数をクラスのインスタンス変数にして、クラス内のどこでも使用できるようにします。
他のデータとは具体的になりますか?すべてのデータはXMLファイルから来ますか? –
@MattWolfeはいすべてのデータはxmlファイルから来ています。私はこのデータを解析し、それを文字列配列に格納しています。 – Dinesh
どのくらいのデータですか?あなたが10,000以上の値を持っていないかぎり、私はすべてのファイルを先にロードする方が良いと思われます。各ファイルを読み込んでそのデータをArrayListに追加するだけです。そしてArrayAdapterでそのArrayListを使用してください。あなたがこれまでに行ったコードを見せてくれたら、助けてくれるように最善の方法を知っているので、もっと助けになるでしょう。 –