I want to let the data to be shown on the edittext first. How can I do it? I've already passed the data to the modify page, and I want to let the data first show on the edittext, then let the user change the title if the user needs to change.
Here are my modify page code:
public class MeTodolistModify extends AppCompatActivity implements View.OnClickListener {
private String student_id,student_name,title,input;
private EditText addtext;
private Button change;
private int position;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_me_todolist_modify);
Bundle bundle = getIntent().getExtras();
title = bundle.getString("title");
position = bundle.getInt("position");
student_id = bundle.getString("student_id");
student_name = bundle.getString("student_name");
createDetail();
}
private void createDetail(){
final FirebaseDatabase db = FirebaseDatabase.getInstance();
final DatabaseReference ref = db.getReference("Student").child(student_id).child("event");
Log.e("MOD",String.valueOf(position));
Log.e("MOD2",title);
change = findViewById(R.id.change);
change.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
EditText addtext = findViewById(R.id.addtext);
input = addtext.getText().toString();
ref.child(Integer.toString(position)).setValue(input);
Intent intent;
switch (v.getId()) {
case R.id.change:
intent = new Intent(MeTodolistModify.this, MeTodolist.class);
intent.putExtra("student_id", student_id );
intent.putExtra("student_name",student_name);
startActivity(intent);
break;
}
}
});
}
#Override
public void onClick(View v) {
}
}
The update code for modify page:
public class MeTodolistModify extends AppCompatActivity implements View.OnClickListener {
private String student_id,student_name,title,input;
private EditText addtext;
private Button change;
private int position;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_me_todolist_modify);
Bundle bundle = getIntent().getExtras();
title = bundle.getString("title");
position = bundle.getInt("position");
student_id = bundle.getString("student_id");
student_name = bundle.getString("student_name");
createDetail();
}
private void createDetail(){
final FirebaseDatabase db = FirebaseDatabase.getInstance();
final DatabaseReference ref = db.getReference("Student").child(student_id).child("event");
Log.e("MOD",String.valueOf(position));
Log.e("MOD2",title);
change = findViewById(R.id.change);
change.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
EditText addtext = findViewById(R.id.addtext);
addtext.setText(title);
input = addtext.getText().toString();
ref.child(Integer.toString(position)).setValue(input);
Intent intent;
switch (v.getId()) {
case R.id.change:
intent = new Intent(MeTodolistModify.this, MeTodolist.class);
intent.putExtra("student_id", student_id );
intent.putExtra("student_name",student_name);
startActivity(intent);
break;
}
}
});
}
#Override
public void onClick(View v) {
}
}
after getting title from bundle
title = bundle.getString("title");
set title to EditText
addtext.setText(title)
later user can change if he wants
If you want to programmatically set data to EditText
addtext.setText("Some text");
Related
I am trying to pass some data from one activity to another and I have made a toast in the other activity to see if data is being passed.When the toast shows up it is blank.I have done everything right and tried many different times with different methods I have also created another app but the problem still stays.It gives me null.
My java code in the first activity
public class titleandcuisine extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
public static final String TITLE_GET = "title";
public static final String CUISINE_GET = "cuisine";
ImageView imageView;
Button button;
Spinner spinner;
EditText dish;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_titleandcuisine);
dish = findViewById(R.id.editText);
spinner = findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,R.array.cuisines,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
button = findViewById(R.id.next);
imageView = findViewById(R.id.close);
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), homepage.class));
}
});
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String text = dish.getText().toString();
String text2 = spinner.getSelectedItem().toString();
Intent data = new Intent(getBaseContext(),imagepost.class);
data.putExtra(TITLE_GET,text);
data.putExtra(CUISINE_GET,text2);
startActivity(data);
}
});
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
Second activity java code
public class reviewactivity extends AppCompatActivity {
TextView cuisine,title;
ImageView displayimage,back;
Uri myUri;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reviewactivity);
Intent intent = getIntent();
String titleget = intent.getStringExtra(titleandcuisine.TITLE_GET);
String cuisineget = intent.getStringExtra(titleandcuisine.CUISINE_GET);
Toast.makeText(this, titleget + cuisineget, Toast.LENGTH_SHORT).show();
cuisine = findViewById(R.id.reviewcuisine);
title = findViewById(R.id.reviewtitle);
back = findViewById(R.id.backtopostvideo);
displayimage = findViewById(R.id.reviewdisplaimage);
// cuisine.setText(cuisineget);
// title.setText(titleget);
// myUri = Uri.parse(uri);
displayimage.setImageURI(myUri);
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(),videopost.class));
}
});
}
}
You need to read the text from the EditText when the button is clicked. Something like:
title = dish.getText().toString(); // Add this
Intent data = new Intent(getBaseContext(),imagepost.class);
data.putExtra(Intent.EXTRA_TEXT, title);
...
One more thing: You are trying to read the Intent.EXTRA_TEXT at the reviewactivity activity. However, nothing is starting that activity (at least within the piece of code that you shared).
I am new to Android development. I have an app in which the user creates multiple names (as if they were players of a game). These "players" appear as a matrix is used in the same activity. (Being possible here to exclude any player).
I want to display all of these players (MainActivity) in another activity (Main2Activity), showing only the first player added and, clicking a button, switch to the second player.
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
RecyclerView recyclerView;
TextView textAdd;
EditText etAdd;
ArrayList<Model> models = new ArrayList<Model>();
MyAdapter myAdapter;
int position;
Button prox;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
prox = findViewById(R.id.prox);
prox.setOnClickListener(new View.OnClickListener() {
//next screen
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
String nome = etAdd.getText().toString();
intent.putExtra("value", nome);
startActivity(intent);
}
});
recyclerView = findViewById(R.id.recyclerView);
textAdd = findViewById(R.id.text_adicionar);
etAdd = findViewById(R.id.et_Adicionar);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
myAdapter = new MyAdapter(getApplicationContext(),
models, new MyAdapter.Onclick() {
#Override
public void onEvent(Model model, int pos) {
position = pos;
etAdd.setText(model.getId());
}
});
recyclerView.setAdapter(myAdapter);
textAdd.setOnClickListener(this);
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.text_adicionar: {
insertItem(String.valueOf(etAdd.getText()));
}
break;
}
}
private void insertItem(String name) {
Gson gson = new Gson();
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", name);
Model model = gson.fromJson(String.valueOf(jsonObject), Model.class);
models.add(model);
myAdapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
public class Main2Activity extends AppCompatActivity implements View.OnClickListener {
Button play;
TextView text_player_name;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
play = findViewById(R.id.play);
text_player_name = findViewById(R.id.text);
play.setOnClickListener(this);
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.play: {
String name = getIntent().getExtras().getString("value");
text_player_name.setText(String.valueOf(name));
}
break;
}
}
}
I'm not sure if I fully understand your question, but are you just looking for a way to pass data from one Activity to another?
If so, use .putExtra() with your Intent for starting the next Activity.
In the onCreate method for your second Activity, use .getExtras() to retrieve the data.
In 1st Activity
Intent intent = new Intent(this, Activity2.class);
intent.putExtra("DataName", data);
startActivity(intent);
In the 2nd Activity
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
String[] dataArray = getIntent().getExtras().get("DataName"));
}
EDIT:
public class Main2Activity extends AppCompatActivity implements View.OnClickListener {
Button play;
TextView text_player_name;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
play = findViewById(R.id.play);
text_player_name = findViewById(R.id.text);
play.setOnClickListener(this);
}
#Override
public void onClick(View v) {
String name = getIntent().getExtras().getString("value");
text_player_name.setText(String.valueOf(name));
}
I'm building an app which ask user to register their name, email, phone no and Blood Type.
Below is my Firebase database structure:
and my Screenshot of app is
How do I add search bar or filters show as per Blood type key , such that user can filters according to Blood Type. If I in requirment of B negative Blood..I'll use drop down menu for Blood I need to search and when pressed on search button will only show me the Blood group registered as B negative in firebase Database i.e as per key blood_group.
Here is my code I use to upload the user details:
public class EnquiryActivity extends AppCompatActivity {
//UI
Button btnRequest;
EditText edtName,edtBlood,edtPlace,edtMobile,edtEmail;
//DB
DatabaseReference mHelper;
FirebaseAuth mAuth;
//progress
ProgressDialog mProgress;
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enquiry);
//initialisation
edtBlood=(EditText)findViewById(R.id.enq_blood);
edtMobile=(EditText)findViewById(R.id.enq_mobile);
edtEmail=(EditText)findViewById(R.id.enq_email);
edtName=(EditText)findViewById(R.id.enq_name);
edtPlace=(EditText)findViewById(R.id.enq_place);
btnRequest=(Button)findViewById(R.id.button2);
//firebase
mHelper= FirebaseDatabase.getInstance().getReference();
final String mCurrentUser=FirebaseAuth.getInstance().getCurrentUser().getUid().toString();
mAuth=FirebaseAuth.getInstance();
//progress
mProgress=new ProgressDialog(this);
mProgress.setTitle("Loading");
mProgress.setMessage("Please wait..");
btnRequest.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mProgress.show();
String blood=edtBlood.getText().toString();
String name=edtName.getText().toString();
String mobile=edtMobile.getText().toString();
String email=edtEmail.getText().toString();
String place=edtPlace.getText().toString();
String temp=blood.toUpperCase();
if(!TextUtils.isEmpty(blood)||!TextUtils.isEmpty(name)||!TextUtils.isEmpty(mobile)||
!TextUtils.isEmpty(place)){
HashMap<String, String> userMap = new HashMap<>();
userMap.put("name", name);
userMap.put("blood_group",blood);
userMap.put("email", email);
userMap.put("mobile", mobile);
userMap.put("place","Location:- " + place);
mHelper.child("Help").child(mCurrentUser).setValue(userMap).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
mProgress.dismiss();
Toast.makeText(getApplicationContext(), "Registered Successfully..!", Toast.LENGTH_LONG).show();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
});
}else{
Toast.makeText(getApplicationContext(),"Please enter the details in all fields",Toast.LENGTH_LONG).show();
}
}
});
}
}
and I retrive the data using below code
/**
* A simple {#link Fragment} subclass.
*/
public class DonorListFragment extends Fragment {
private RecyclerView mDonorList;
private DatabaseReference mFriendsDatabase;
private DatabaseReference mUsersDatabase;
private FirebaseAuth mAuth;
private ProgressDialog mDonorProgress;
private String mCurrent_user_id;
private View mMainView;
public DonorListFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mMainView = inflater.inflate(R.layout.fragment_donor_list, container, false);
mDonorList = (RecyclerView)mMainView.findViewById(R.id.donor_recyclerview);
mAuth = FirebaseAuth.getInstance();
mCurrent_user_id = mAuth.getCurrentUser().getUid();
mDonorProgress=new ProgressDialog(getContext());
mDonorProgress.setTitle("Logging In");
mDonorProgress.setMessage("Please Wait...");
mDonorProgress.setCanceledOnTouchOutside(false);
mDonorProgress.show();
mUsersDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
mUsersDatabase.keepSynced(true);
mDonorList.setHasFixedSize(true);
LinearLayoutManager linearVertical = new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL,false);
mDonorList.setLayoutManager(linearVertical);
DividerItemDecoration mDividerItemDecoration = new DividerItemDecoration(
mDonorList.getContext(),
linearVertical.getOrientation()
);
mDonorList.addItemDecoration(mDividerItemDecoration);
// Inflate the layout for this fragment
return mMainView;
}
#Override
public void onStart() {
super.onStart();
FirebaseRecyclerAdapter<Donors, DonorsViewHolder> friendsRecyclerViewAdapter = new FirebaseRecyclerAdapter<Donors, DonorsViewHolder>(
Donors.class,
R.layout.users_single_layout,
DonorsViewHolder.class,
mUsersDatabase
) {
#Override
protected void populateViewHolder(final DonorsViewHolder donorsViewHolder, Donors donors, int i) {
donorsViewHolder.setDate(donors.getDate());
final String list_user_id = getRef(i).getKey();
mUsersDatabase.child(list_user_id).addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
final String userName = dataSnapshot.child("name").getValue().toString();
String blood=dataSnapshot.child("blood_group").getValue().toString();
String phone=dataSnapshot.child("mobile").getValue().toString();
final String email=dataSnapshot.child("email").getValue().toString();
String address=dataSnapshot.child("place").getValue().toString();
mDonorProgress.hide();
donorsViewHolder.setName(userName);
donorsViewHolder.setBlood(blood);
donorsViewHolder.setEmail(email);
donorsViewHolder.setAddress(address);
donorsViewHolder.setPhone(phone);
final String uri=phone;
donorsViewHolder.mView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
CharSequence options[] = new CharSequence[]{"Email", "Call"};
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("Select Options");
builder.setItems(options, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
//Click Event for each item.
if(i == 0){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { email });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
getActivity().startActivity(Intent.createChooser(intent, ""));
}
if(i == 1){
Intent callIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+uri));
// callIntent.setData(Uri.parse("tel:"+uri));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getActivity().startActivity(callIntent);
}
}
});
builder.show();
}
});
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
};
mDonorList.setAdapter(friendsRecyclerViewAdapter);
}
// viewholder class..
public static class DonorsViewHolder extends RecyclerView.ViewHolder {
View mView;
public DonorsViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setBlood(String blood){
TextView userStatusView = (TextView) mView.findViewById(R.id.user_single_blood);
userStatusView.setText(blood.toUpperCase());
}
public void setName(String name){
TextView userNameView = (TextView) mView.findViewById(R.id.user_single_name);
userNameView.setText(name);
}
public void setEmail(String email){
TextView userNameView = (TextView) mView.findViewById(R.id.user_single_email);
userNameView.setText(email);
}
public void setPhone(String phone){
TextView userNameView = (TextView) mView.findViewById(R.id.user_single_phone);
userNameView.setText(phone);
}
public void setAddress(String address) {
TextView userNameView = (TextView) mView.findViewById(R.id.user_single_address);
address.toUpperCase();
userNameView.setText(address.toUpperCase());
}
public void setDate(String date){
}
}
}
To achieve what you want, you need to execute a query which should look like this:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference usersRef = rootRef.child("Users");
Query query = usersRef.orderByChild("blood_group").equalTo("Blood Group: " + newText);
In which newText variable can hold any value you want, B positive as well as B negative.
So everytime you create a search you should return a new query. So according to this, every time you want to filter on a new condition, you will need to:
Create a new query based on the new filter:
Query query = usersRef.orderByChild("blood_group").equalTo("Blood Group: " + newText);
Attach a listener to this new created query.
Create a new adapter with the results of this new created query, or update the existing one using notifydatasetchanged() method.
I'm having problems storing intent extras from my previous activity when I use another intent to open an activity and return the result.
Logic:
Activity A: receive string from check box, uses intent hasExtra to pass to activity b
Activity B: List of edit text fields with buttons to activity c
Activity C: uses intent extra to get string and pass to another editTextField in activity b
Problem is that I keep losing the intentExtra from a to b.
I apologise if my description is not thorough, I'm new to Java.
Activity A
public class PipesInspection extends AppCompatActivity{
private static final String TAG = "PipesInspection";
ArrayList<String> pipesInspectionSelection = new ArrayList<String>();
Button nextButtonToPost;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.residential_pipes_inspection_lv_selected);
Log.d(TAG, "onCreate: starting");
initialiseWidgets();
}
public void initialiseWidgets(){
nextButtonToPost = (Button) findViewById(R.id.nextButton);
nextButtonToPost.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String final_category_selection = "";
for (String Selections : pipesInspectionSelection){
final_category_selection = final_category_selection + Selections + ", ";
}
Log.v(TAG,"gotten text: " + final_category_selection);
String selectedChoices = pipesInspectionSelected.getText().toString();
Intent pipesInspectionIntent = new Intent(v.getContext(), PostAJobActivity.class);
pipesInspectionIntent.putExtra("selectedChoices", selectedChoices);
v.getContext().startActivity(pipesInspectionIntent);
}
});
}
}
Activity B
public class PostAJobActivity extends AppCompatActivity {
private static final String TAG = "PostAJobActivity";
EditText jobTitle, jobDescription, jobLocation;
String location, title;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post_a_job);
Log.d(TAG, "onCreate: starting");
jobDescription = (EditText)findViewById(R.id.input_job_description);
mapsButton = (ImageButton) findViewById(R.id.mapButton);
mapsButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(mContext, LaunchMapsActivity.class);
startActivity(intent);
}
});
getIntentExtras();
}
public void getIntentExtras(){
jobLocation = (EditText) findViewById(R.id.location);
Intent intentLocation =getIntent();
location= intentLocation.getStringExtra("location");
jobLocation.setText(location);
jobTitle = (EditText) findViewById(R.id.title);
Intent pipesInspectionIntent = getIntent();
title = pipesInspectionIntent.getStringExtra("selectedChoices");
jobTitle.setText(title);
}
}
Activity C
public class PlaceListAdapter extends RecyclerView.Adapter<PlaceListAdapter.PlaceViewHolder> {
private Context mContext;
private PlaceBuffer mPlaces;
public PlaceListAdapter(Context context, PlaceBuffer places) {
this.mContext = context;
this.mPlaces = places;
}
#Override
public PlaceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// Get the RecyclerView item layout
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.maps_item_place_card, parent, false);
return new PlaceViewHolder(view);
}
#Override
public void onBindViewHolder(final PlaceViewHolder holder, int position) {
String placeName = mPlaces.get(position).getName().toString();
String placeAddress = mPlaces.get(position).getAddress().toString();
holder.nameTextView.setText(placeName);
holder.addressTextView.setText(placeAddress);
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intentLocation = new Intent(v.getContext(), PostAJobActivity.class);
intentLocation.putExtra("location",holder.nameTextView.getText().toString()+
", " + holder.addressTextView.getText().toString());
v.getContext().startActivity(intentLocation);
}
});
}
I think this article may be helpful
https://developer.android.com/training/basics/intents/result.html
I am not sure I understand the problem correctly...activity A starts first and passes data to activity B which invokes activity C and gets data from it return to activity B which uses the data collected from both activities to do something
....If this is your problem you should not start activity C the normal way you should use startActivityforresult() form activity B to start activty C
and wait for it to finish then return to B with the data collected from C....starting the activity B from activity C will create new instance of B without having the data collected form A while using this way the instance of B with data from A will wait to C to finish and take the data from it in addition to that move the getIntentExtras() function inside the onClick()
I have a simple app with 50 articles, my previous and next button work good in all choices BUT when the user goes to the end (at 50th article) the app can't load again from the beginning the 1st article.
Thanks for any help, here is my code:
I don't know if needs more cede for to be clear, cause I am a newbie.
public class StoryActivity extends AppCompatActivity {
public static final String TAG = StoryActivity.class.getSimpleName();
private Story mStory = new Story();
private ImageView mImageView;
private TextView mTextView;
private Page mCurrentPage;
private String mName;
private Button mPreviousButton;
private Button mNextButton;
private ScrollView mScrollView;
private Button mStartButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_story2);
//Intent intent = getIntent();
//mName = intent.getStringExtra(getString(R.string.key_name));
if(mName == null){
mName = "";
}
Log.d(TAG, mName);
mImageView = (ImageView)findViewById(R.id.storyImageView);
mTextView = (TextView)findViewById(R.id.storyTextView);
mPreviousButton = (Button)findViewById(R.id.previousButton);
mNextButton = (Button)findViewById(R.id.nextButton);
mTextView.setMovementMethod(new ScrollingMovementMethod());
loadPage(0);
}
private void loadPage(int choice){
mCurrentPage = mStory.getPage(choice);
Drawable drawable = getResources().getDrawable(mCurrentPage.getImageId());
mImageView.setImageDrawable(drawable);
String pageText = mCurrentPage.getText();
//add the name if placeholder included.
//pageText = String.format(pageText,mName);
mTextView.setText(pageText);
if(mCurrentPage.isSingle()){
mPreviousButton.setVisibility(View.VISIBLE);
mNextButton.setText("");
mNextButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
loadPage(0);
}
});
}else{
mPreviousButton.setText(mCurrentPage.getChoices().getText1());
mNextButton.setText(mCurrentPage.getChoices().getText2());
mPreviousButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int previousPage = mCurrentPage.getChoices().getPreviousPage();
loadPage(previousPage);
}
});
mNextButton.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
int nextPage = mCurrentPage.getChoices().getNextPage();
loadPage(nextPage);
}
});
}}
}