So I've just started screwing with the sdk and was working on changing activities, more specifically, how to maintain data from one activity to another since I haven't found anything like the main class in java. The main problem is i cant figure out how to dynamically update textviews.
so on to the code, I can provide the xml files but I figured the data there could be inferred for the most part.
Menu (Main class):
+ Show Spoiler +
package com.notes;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class Menu extends Activity implements OnClickListener {
/** Called when the activity is first created. */
private EditText enterText;
private Button startViewer;
//Stores Notes
ArrayList<String> notes = new ArrayList<String>();
String readNotes;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startViewer = (Button) findViewById(R.id.viewNotes);
startViewer.setOnClickListener(this);
}
//Save button
public void saveMeth(View view){
enterText = (EditText) findViewById(R.id.text);
for(int i = 0; i < notes.size(); i++)
{
if(notes.get(i) == null)
{
notes.add(i, enterText.getText().toString());
}
}
enterText.setText("");
}
//Changes to viewNotes activity
@Override
public void onClick
(View view)
{
for(int i = 0; i<notes.size(); i++)
{
readNotes = readNotes +"\n" + notes.get(i);
}
Intent i = new Intent(this,ViewNotes.class);
i.putStringArrayListExtra("notes", notes);
startActivity(i);
}
}
ViewNotes (Trying to view saved text)
+ Show Spoiler +
package com.notes;
import java.util.ArrayList;
import com.notes.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class ViewNotes extends Activity{
ArrayList<String> notesAR = new ArrayList<String>();
String notes;
TextView scroll;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view);
scroll = (TextView) this.findViewById(R.id.scrollText);
Intent j = getIntent();
//I guess this is how you maintain data across activities
notesAR = j.getStringArrayListExtra("notes");
//Converts ArrayList to String
for(int i = 0; i<notesAR.size(); i ++)
{
notes = notesAR.get(i) + "\n";
}
//Trying to set textView text here
scroll.setText(scroll.getText()+"\n"+notes);
}
}