Advertisement
kemkriszt

ac

Mar 20th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. public class TysActivity extends Activity{
  2.  
  3.     ...........
  4.     private TextView usrView;
  5.     private ImageView addButton;
  6.     private ListView lv;
  7.     //URLs
  8.     .......
  9.     //Loading stories
  10.     private final int ten = 10;
  11.     private int counter = 1;
  12.     private String usrName;
  13.     private StoryAdapter adapter;
  14.     @Override
  15.     protected void onCreate(Bundle savedInstanceState) {
  16.         super.onCreate(savedInstanceState);
  17.         setContentView(R.layout.tys_activity);
  18.         Intent i = getIntent();
  19.         counter = 1;
  20.         usrName = i.getStringExtra(MainActivity.EXTRA_USER);
  21.         usrView = (TextView)findViewById(R.id.userV);
  22.         usrView.setText(usrName);
  23.         lv = (ListView) findViewById(R.id.list);
  24.         //Add onClickListener to textView
  25.         usrView.setOnClickListener(new OnClickListener() { 
  26.             @Override
  27.             public void onClick(View v) {
  28.                 refresh();
  29.                 Toast.makeText(getApplicationContext(), "Refreshed", Toast.LENGTH_SHORT).show();       
  30.             }
  31.         });
  32.         //Add onClickListener to image view
  33.         addButton = (ImageView) findViewById(R.id.addB);
  34.         addButton.setOnClickListener(new OnClickListener() {
  35.             ......
  36.         });
  37.         //create adapter
  38.         adapter = new StoryAdapter();
  39.         //load 10 story
  40.         load();
  41.         //add adapter
  42.         lv.setAdapter(adapter);
  43.     }
  44.    
  45.     @Override
  46.     protected void onResume() {
  47.         super.onResume();
  48.         adapter.notifyDataSetChanged();
  49.         lv.invalidate();
  50.     }
  51.  
  52.     private void load(){
  53.         new HttpGetAsyncTask(getApplicationContext()).execute(url_get_id,url_get_username,url_get_title,url_get_story);
  54.        
  55.     }
  56.     private void more(){
  57.         counter++;
  58.         load();
  59.     }
  60.     private void refresh(){
  61.         counter = 1;
  62.         load();
  63.     }
  64.     .....
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement