Heading ##There is my source code , but it has list without web service ?
what's wrong has no idea
My Detail view with viewpager public class DviewActivity extends FragmentActivity {
public static ArrayList<Course> courselist = invokeDetailview();
static int NUM_ITEMS;
MyAdapter mAdapter;
ViewPager mPager;
ProgressDialog prgDialog;
TextView errMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dview);
prgDialog = new ProgressDialog(this);
prgDialog.setMessage("Loading Data...");
prgDialog.setCancelable(false);
//courselist.add(new Course(1,"aaa","bbb"));
//courselist.add(new Course(2,"bbb","bbb"));
//courselist.add(new Course(3,"ccc","bbb"));
//NUM_ITEMS = courselist.size();
NUM_ITEMS = courselist.size();
mAdapter = new MyAdapter(getSupportFragmentManager());
mPager = (ViewPager)findViewById(R.id.viewPager);
mPager.setAdapter(mAdapter);
//CustomlistAdapter adapter = new CustomlistAdapter(this,courselist);
//ListView listview = (ListView)findViewById(R.id.listView1);
//listview.setAdapter(adapter);
}
protected static ArrayList<Course> invokeDetailview(){
//prgDialog.show();
final ArrayList<Course> result = new ArrayList<Course>();
AsyncHttpClient Client = new AsyncHttpClient();
Client.get("http://ift.tt/1Bq99lM", new AsyncHttpResponseHandler(){
// When the response returned by REST has Http response code other than '200'
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable
error) {
System.out.println("OnFailure");
// TODO Auto-generated method stub
// Hide Progress Dialog
// prgDialog.hide();
// When Http response code is '404'
if(statusCode == 404){
// Toast.makeText(getApplicationContext(), "Requested resource not found", Toast.LENGTH_LONG).show();
}
// When Http response code is '500'
else if(statusCode == 500){
// Toast.makeText(getApplicationContext(), "Something went wrong at server end", Toast.LENGTH_LONG).show();
}
// When Http response code other than 404, 500
else{
// Toast.makeText(getApplicationContext(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet or remote server is not up and running]", Toast.LENGTH_LONG).show();
}
}
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
// TODO Auto-generated method stub
try{
String response = new String(responseBody);
JSONArray gsonarr = new JSONArray(response);
result.addAll(Course.fromJSON(gsonarr));
}catch(JSONException e){
// TODO Auto-generated catch block
// Toast.makeText(getApplicationContext(), "Error Occured [Server's JSON response might be invalid]!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
return result;
}
FragmentStateAdapter & Fragment public static class MyAdapter extends FragmentStatePagerAdapter { //public ArrayList CourseList = new ArrayList(); public MyAdapter(FragmentManager fm) { super(fm);
}
@Override
public int getCount()
{
return NUM_ITEMS;
}
@Override
public Fragment getItem(int position)
{
return ArrayListFragment.newInstance(courselist,position);
}
}
public static class ArrayListFragment extends Fragment
{
int mNum;
String mSEQ;
String mHAWB;
String mMAWB;
/**
* Create a new instance of CountingFragment, providing "num" as an
* argument.
*/
static ArrayListFragment newInstance(ArrayList<Course> courselist,int position)
{
//NUM_ITEMS = courselist.size();
ArrayListFragment f = new ArrayListFragment();
//Bundle args = new Bundle();
//args.putInt("num", num);
//f.setArguments(args);
Bundle bundle = new Bundle();
bundle.putString("SEQ", Integer.toString(courselist.get(position).SEQ));
bundle.putString("HAWB", courselist.get(position).HAWB);
bundle.putString("MAWB", courselist.get(position).MAWB);
f.setArguments(bundle);
return f;
}
/**
* When creating, retrieve this instance's number from its arguments.
*/
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//mNum = getArguments() != null ? getArguments().getInt("num") : 1;
mSEQ = getArguments() != null ? getArguments().getString("SEQ") : "String";
mHAWB = getArguments() != null ? getArguments().getString("HAWB") : "String";
mMAWB = getArguments() != null ? getArguments().getString("MAWB") : "String";
}
/**
* The Fragment's UI is just a simple text view showing its instance
* number.
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.detailview, container, false);
TextView tvSEQ = (TextView) v.findViewById(R.id.tvSEQ);
TextView tvHAWB = (TextView) v.findViewById(R.id.tvHAWB);
TextView tvMAWB = (TextView) v.findViewById(R.id.tvMAWB);
tvSEQ.setText(mSEQ);
tvHAWB.setText(mHAWB);
tvMAWB.setText(mMAWB);
return v;
}
## Heading ##
}
Aucun commentaire:
Enregistrer un commentaire