私はfacebook
(いくつかの名前とIDの)からいくつかのデータを返すアンドロイドのアプリを持っています。このデータを返すと直ぐに、私はこのリストのすべての名前を設定するためにアダプターを使います。 私はonCreate()
でこの作業を行っています。最初にメソッドgetData()
を使用して、Facebookからいくつかの名前を返し、その後、私はそのアダプタを呼び出します。android appのアダプターの問題
getData()
は、array
のStringsに、アダプタで設定される名前を返します。このアダプタでは、この配列に対して何らかの処理が行われます。
ウェブからこれらの名前を返す方法この部分は遅く動作し、配列は時間通りには埋め込まれないので、アダプタが呼び出されると配列はまだ空で、強制的に閉じる。ここで
private String[] mStrings;
private String[] fName;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.invitefriends);
....................
/*In here I request for friends from facebook which ae set up in an array*/
mAsyncRunner.request("me/friends", new SampleRequestListener());
/*here is the adapter that processes the arrays returned in SampleRequestListener*/
adapter=new LazyAdapter1(this, mStrings,fName);
list.setAdapter(adapter);
}
/
は、いくつかの配列ついに/public class SampleRequestListener extends BaseRequestListener{
int i;
public void onComplete(final String response, final Object state){
friends = new ArrayList<Friends>();
try{
Log.d("facebook-example","Response: " + response.toString());
JSONObject json = Util.parseJson(response);
JSONArray array = json.optJSONArray("data");
if(array!=null){
for(int i=0; i<array.length(); i++)
{
String name=array.getJSONObject(i).getString("name");
String id= array.getJSONObject(i).getString("id");
Friends f=new Friends(name,id);
friends.add(f);
Log.d(name,id);
}
mStrings = new String[friends.size()];
for(int i=0; i< mStrings.length; i++){
mStrings[i] = "http://graph.facebook.com/"+friends.get(i).getId()+"/picture?type=small";
}
fName = new String[friends.size()];
for(int i=0; i<friends.size(); i++)
{
fName[i]=friends.get(i).getName();
}
}
}
catch(JSONException e)
{
//do nothing
}
catch(FacebookError e)
{
e.getMessage();
}
}
}
とにFacebookのから名前を返すんSampleRequestListenerあるアダプタの体である:
これは、私はそれを行う方法であります:
public class LazyAdapter1は、BaseAdapter {
private Activity activity;
private String[] data;
private String[] nume;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public LazyAdapter1(Activity a, String[] d, String[] f) {
activity = a;
data=d;
nume=f;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder{
public TextView text;
public ImageView image;
}
public View getView(int position, View convertView, ViewGroup parent) {
//........
}
}
問題は、彼らはまだ空ですので、私はそれらのアダプタを持って行動しようとすると、mStrings[]
とfName[]
は、バックグラウンドスレッドで時間内に返却されていないということです。
だから、誰かが、私はAsyncTaskクラスを使用してカスタムクラスを拡張し、右??おかげ
購入リンク! !!!! – adrian
問題は、アダプタの設定を遅らせる方法がわからないことです! – adrian
これを上書きした第1のdoInBackgroundこの部分のすべてのデータをフェッチする、2はonProgressUpdateでした。ユーザにはuiで、最後にはonPostExecuteの部分は、バックグラウンドプロセスで準備された配列です。アダプター。あなたは、バックグラウンドプロセスが完了したときに時間を設定する必要はありません、それはonPostExecuteメソッドを呼び出すでしょう – Pratik