0

I have an application that parses XML from an online XML file and displays it in a listview. The user can then click on an item and view the full story. This all works fine but I would like for users to be able to save certain articles so that they can read them at a later date or offline. I assume this is fairly simple but am having trouble finding anything to lead me in the right direction. Below is the activity that displays the single news article.

public class SingleActivity  extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.single_list_item);

        // getting intent data
        Intent in = getIntent();

        // Get XML values from previous intent
        String title = in.getStringExtra("name");
        String date = in.getStringExtra("date");
        String content = in.getStringExtra("content");

        // Displaying all values on the screen
        TextView lblName = (TextView) findViewById(R.id.name_label);
        TextView lblDate = (TextView) findViewById(R.id.date_label);
        TextView lblCont = (TextView) findViewById(R.id.content_label);

        lblName.setText(title);
        lblDate.setText(date);
        lblCont.setText(Html.fromHtml(content));
    }   
}
Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
Zach
  • 1,964
  • 2
  • 17
  • 28

2 Answers2

2

You can make use of SQLite database. Give an option for a user an option to save. You can use a button or an image button or anything which can raise an event. When event is raised on it just save them to database. If you are not OK with DB get an example here. Your modified code will look like this.

 public class SingleActivity  extends Activity {

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.single_list_item);

        // getting intent data
        Intent in = getIntent();

        // Get XML values from previous intent
        String title = in.getStringExtra("name");
        String date = in.getStringExtra("date");
        String content = in.getStringExtra("content");

        // Displaying all values on the screen
        TextView lblName = (TextView) findViewById(R.id.name_label);
        TextView lblDate = (TextView) findViewById(R.id.date_label);
        TextView lblCont = (TextView) findViewById(R.id.content_label);

        lblName.setText(title);
        lblDate.setText(date);
        lblCont.setText(Html.fromHtml(content));

        Button b = (Button)  findViewById(R.id.savebutton);
        b.setonclicklistsener() {
             saveToDB(lblName's text, lblDate's text, lblCont's text);
        }


    }

     public void saveToDB(lblName's text, lblDate's text, lblCont's text){

           // do database stuff here    

     }

}
Community
  • 1
  • 1
Vinay
  • 6,891
  • 4
  • 32
  • 50
0

You can use sqlite for this particular case http://www.codeproject.com/Articles/119293/Using-SQLite-Database-with-Android

petrumo
  • 1,116
  • 9
  • 18