6
我對我的android應用程序有一種情況。場景是我使用的是一個視圖頁適配器翼起我有3個頁面實際上是片段。我的問題是,我想從對話框活動中更新這些對象。該對話框活動包含我想要更新片段的onclick事件列表。如何通過另一個活動刷新viewpageadapter中的一個片段
首先是可能的,如果是的話,請切入並幫助我。
乾杯 拉夫
這是我的看法頁適配器
/*
* Copyright (C) 2012 Gaurav Rawat
*
*/
package com.punksrant.ifinddryday.adapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import com.punksrant.ifinddryday.fragment.AllFragment;
import com.punksrant.ifinddryday.fragment.HomeFragment;
import com.punksrant.ifinddryday.fragment.SynchFragment;
import com.punksrant.ifinddryday.utils.IFindDryDaysConstants;
import com.viewpagerindicator.TitleProvider;
public class ViewPagerAdapter extends FragmentPagerAdapter implements
TitleProvider {
private static String[] titles = IFindDryDaysConstants.titles;
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public String getTitle(int position) {
return titles[position % titles.length].toUpperCase();
}
@Override
public int getCount() {
return titles.length;
}
@Override
public Fragment getItem(int position) {
Fragment fragment;
switch (position) {
case 0:
fragment = HomeFragment.newInstance();
break;
case 1:
fragment = AllFragment.newInstance();
break;
case 2:
fragment = SynchFragment.newInstance(titles[position
% titles.length]);
break;
default:
fragment = HomeFragment.newInstance();
}
return fragment;
}
}
' and in this I want to refresh the home fragment from my dialog class
'/*
* Copyright (C) 2012 Gaurav Rawat
*
*/
package com.punksrant.ifinddryday.activity;
import roboguice.inject.ContentView;
import roboguice.inject.InjectView;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.github.rtyley.android.sherlock.roboguice.activity.RoboSherlockFragmentActivity;
import com.google.inject.Inject;
import com.punksrant.ifinddryday.model.Coordinates;
import com.punksrant.ifinddryday.utils.DryDayJSONResParser;
import com.punksrant.ifinddryday.utils.IFindDryDayViewUtils;
@ContentView(R.layout.statedialog)
public class Dialog extends RoboSherlockFragmentActivity {
@InjectView(R.id.dialogList)
ListView listView;
@Inject
SharedPreferences preferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] states = DryDayJSONResParser.getSupportedStates();
listView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, states));
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String state = ((TextView) view).getText().toString();
Coordinates coordinates = IFindDryDayViewUtils
.getCoordinatesFromPreferences(preferences);
coordinates.setState(state);
IFindDryDayViewUtils.updateCityFromLocation(coordinates,
preferences);
finish();
}
});
}
},
你的視圖頁適配器在哪裏?你可以發佈一些持有viewpager的活動代碼嗎? – gutiory 2012-04-24 07:52:17
Hi @gutiory會將代碼粘貼回家,實際上,jist是我正在使用Jake的ViewPagerIndicator庫.http://github.com/JakeWharton/Android-ViewPagerIndicator,其中的片段是從fragmentpageadapter中添加的。請儘快發佈代碼我回來了。 – 2012-04-24 10:21:28
這是我的查看頁面適配器 – 2012-04-24 14:11:19