Create ImageButton in seperate activity when Save button is clicked? - java

I'm trying to do something slightly out of the ordinary. I have an Add a Profile page where a user can add multiple profiles. I want to represent these profiles as circles (ImageButtons) on the homepage.
Much like this:
So when a user saves a profile, how could I add one of these circles onto this horizontal scroll view? I would like the created circle to have a letter inside it from the first letter of the created clients name.
I think this would require me to have all 26 letters of the alphabet already created, but this is no problem.
Any suggestions on how to do this? I'm sorry if I'm not clear, I'd be happy to post any more code or clarify anything. The database I use is Firebase. I'm running the latest version of Android Studio.
Any help is greatly appreciated, cheers guys!
AddAProfile.java:
public class AddProfileActivity extends AppCompatActivity {
EditText etName;
EditText etCareer;
CheckBox cbTech;
CheckBox cbMedi;
CheckBox nfRenewableEnergy;
CheckBox nfGoogle;
CheckBox cfNovartis;
CheckBox nfTesla;
CheckBox lrsFB;
CheckBox lrsAAPL;
CheckBox lrsYHOO;
CheckBox cbEURUSD;
CheckBox lrcuUSDRUB;
CheckBox lrcoSILVER;
CheckBox lrcoGOLD;
CheckBox lrcuGBPUSD;
CheckBox lriNSDQ;
CheckBox lriSP500;
Button bSave;
DatabaseReference databaseClients;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_profile);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
databaseClients = FirebaseDatabase.getInstance().getReference("clients");
etName = (EditText) findViewById(R.id.etName);
etCareer = (EditText) findViewById(R.id.etCareer);
cbTech = (CheckBox) findViewById(R.id.cbTech);
cbMedi = (CheckBox) findViewById(R.id.cbMedi);
nfRenewableEnergy = (CheckBox) findViewById(R.id.nfRenewableEnergy);
nfGoogle = (CheckBox) findViewById(R.id.nfGoogle);
cfNovartis = (CheckBox) findViewById(R.id.cfNovartis);
nfTesla = (CheckBox) findViewById(R.id.nfTesla);
lrsFB = (CheckBox) findViewById(R.id.lrsFB);
lrsAAPL = (CheckBox) findViewById(R.id.lrsAAPL);
lrsYHOO = (CheckBox) findViewById(R.id.lrsYHOO);
cbEURUSD = (CheckBox) findViewById(R.id.cbEURUSD);
lrcuUSDRUB = (CheckBox) findViewById(R.id.lrcuUSDRUB);
lrcoSILVER = (CheckBox) findViewById(R.id.lrcoSILVER);
lrcoGOLD = (CheckBox) findViewById(R.id.lrcoGOLD);
lrcuGBPUSD = (CheckBox) findViewById(R.id.lrcuGBPUSD);
lriNSDQ = (CheckBox) findViewById(R.id.lriNSDQ);
lriSP500 = (CheckBox) findViewById(R.id.lriSP500);
bSave = (Button) findViewById(R.id.bSave);
ImageButton bSettingsBlack = (ImageButton) findViewById(R.id.ibSettingsBlack);
ImageButton bEconCalBlack = (ImageButton) findViewById(R.id.ibEconCalBlack);
ImageButton bLiveRates = (ImageButton) findViewById(R.id.ibLiveRates);
ImageButton bNewsBlack = (ImageButton) findViewById(R.id.ibNewsBlack);
bSettingsBlack.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(AddProfileActivity.this, SettingsActivity.class));
}
});
bEconCalBlack.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(AddProfileActivity.this, WebViewActivity.class));
}
});
bLiveRates.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(AddProfileActivity.this, sortingrates.class));
}
});
bNewsBlack.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(AddProfileActivity.this, HomePageNews.class));
}
});
bSave.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
bSave();
}
});
}
private void bSave(){
String name = etName.getText().toString().trim();
String career = etCareer.getText().toString().trim();
Boolean techCB = cbTech.isChecked();
Boolean mediCB = cbMedi.isChecked();
Boolean renewableEnergyNF = nfRenewableEnergy.isChecked();
Boolean googleNF = nfGoogle.isChecked();
Boolean novartisNF = cfNovartis.isChecked();
Boolean teslaNF = nfTesla.isChecked();
Boolean fbLRS = lrsFB.isChecked();
Boolean applLRS = lrsAAPL.isChecked();
Boolean yhooLRS = lrsYHOO.isChecked();
Boolean eurusdCB = cbEURUSD.isChecked();
Boolean usdrubCU = lrcuUSDRUB.isChecked();
Boolean silverCO = lrcoSILVER.isChecked();
Boolean goldCO = lrcoGOLD.isChecked();
Boolean gbpusdCU = lrcuGBPUSD.isChecked();
Boolean nsdqI = lriNSDQ.isChecked();
Boolean sp500I = lriSP500.isChecked();
if(!TextUtils.isEmpty(name)){
String id = databaseClients.push().getKey();
Clients clients = new Clients(id, name, career, techCB, mediCB, renewableEnergyNF, googleNF,
novartisNF, teslaNF, fbLRS, applLRS, yhooLRS, eurusdCB, usdrubCU, silverCO,
goldCO, gbpusdCU, nsdqI, sp500I );
databaseClients.child(id).setValue(clients);
Toast.makeText(this, "Client added", Toast.LENGTH_LONG).show();
startActivity(new Intent(AddProfileActivity.this, AddProfileActivity.class));
}else{
Toast.makeText(this, "Please enter your name", Toast.LENGTH_LONG).show();
}
}
}
EDIT (What I've tried):
I tired with other buttons as an experiment to change the image as I couldn't figure out to straight up create it.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main17);
ImageView view = (ImageView) findViewById(R.id.imageView3);
view.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
ImageView imageView = (ImageView) view;
assert(R.id.imageView3 == imageView.getId());
Integer integer = (Integer) imageView.getTag();
integer = integer == null ? 0 : integer;
switch(integer) {
case R.drawable.circlesambergrey2:
imageView.setImageResource(R.drawable.bell);
imageView.setTag(R.drawable.bell);
break;
case R.drawable.bell:
default:
imageView.setImageResource(R.drawable.circlesambergrey2);
imageView.setTag(R.drawable.circlesambergrey2);
break;}
}
});
}
I've also thought that the user could select the image button with the correct letter from a spinner. This is what I am currently trying! Cheers.

Related

Where would I put an intent to send the data from the radio button to the textview in the 2nd activity?

This is my code for the pizza app through updating I wanted to understand where I the data gathered from clicking a radiobutton or a checkbox using Intent will be placed here then moved to the 2nd activity? I just want to know where the Intent be placed in this code?
First Activity
public class MainActivity extends AppCompatActivity {
private Button button;
private RadioGroup g1;
private CheckBox cb1, cb2, cb3, cb4, cb5, cb6;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
g1 = (RadioGroup) findViewById(R.id.G1);
cb1 = (CheckBox) findViewById(R.id.cb1);
cb2 = (CheckBox) findViewById(R.id.cb2);
cb3 = (CheckBox) findViewById(R.id.cb3);
cb4 = (CheckBox) findViewById(R.id.cb4);
cb5 = (CheckBox) findViewById(R.id.cb5);
cb6 = (CheckBox) findViewById(R.id.cb6);
g1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.rb1)
{
Toast.makeText(MainActivity.this, "Small", Toast.LENGTH_SHORT).show();
}
if (checkedId == R.id.rb2)
{
Toast.makeText(MainActivity.this, "Medium", Toast.LENGTH_SHORT).show();
}
if (checkedId == R.id.rb3)
{
Toast.makeText(MainActivity.this, "Large", Toast.LENGTH_SHORT).show();
}
}
});
cb1.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
if (cb1.isChecked()){
Toast.makeText(MainActivity.this, "Pepperoni", Toast.LENGTH_SHORT).show();
}
}
});
cb2.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
if (cb2.isChecked()){
Toast.makeText(MainActivity.this, "Olive", Toast.LENGTH_SHORT).show();
}
}
});
cb3.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
if (cb3.isChecked()){
Toast.makeText(MainActivity.this, "Mushroom", Toast.LENGTH_SHORT).show();
}
}
});
cb4.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
if (cb4.isChecked()){
Toast.makeText(MainActivity.this, "Extra Cheese", Toast.LENGTH_SHORT).show();
}
}
});
cb5.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
if (cb5.isChecked()){
Toast.makeText(MainActivity.this, "Chicken", Toast.LENGTH_SHORT).show();
}
}
});
cb6.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
if (cb6.isChecked()){
Toast.makeText(MainActivity.this, "Green Pepper", Toast.LENGTH_SHORT).show();
}
}
});
button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
openActivity2();
}
});
}
public void openActivity2(){
Intent intent = new Intent(this, Activity2.class);
startActivity(intent);
}
}
this is my code for my radiobuttons where do I put the intent to send the data gathered from here to the textView in the second activity?
Second Activity
public class Activity2 extends AppCompatActivity {
EditText editName, editPhone, editEmail, editAddress;
TextView total;
Button buttonSubmit;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);
editName = (EditText) findViewById(R.id.editName);
editPhone = (EditText) findViewById(R.id.editPhone);
editEmail = (EditText) findViewById(R.id.editEmail);
editAddress = (EditText) findViewById(R.id.editAddress);
total = (TextView) findViewById(R.id.total);
buttonSubmit = (Button) findViewById(R.id.button2);
buttonSubmit.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
String name = editName.getText().toString();
String phone = editPhone.getText().toString();
String email = editEmail.getText().toString();
String address = editAddress.getText().toString();
total.setText("Name:\t" + name + "\nPhone:\t" + phone +"\nEmail:\t" + email + "\nAddress:\t" + address);
}
});
}
}
where do I place the getIntent()?
if I understood correctly you want to send the size of the pizza to the second Activity when user select Size from RadioButton for that you can put extra string on the onCheckedChanged method and start your second Activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
g1 = (RadioGroup) findViewById(R.id.G1);
cb1 = (CheckBox) findViewById(R.id.cb1);
cb2 = (CheckBox) findViewById(R.id.cb2);
cb3 = (CheckBox) findViewById(R.id.cb3);
cb4 = (CheckBox) findViewById(R.id.cb4);
cb5 = (CheckBox) findViewById(R.id.cb5);
cb6 = (CheckBox) findViewById(R.id.cb6);
g1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
String size = "";
if (checkedId == R.id.rb1) {
Toast.makeText(MainActivity.this, "Small", Toast.LENGTH_SHORT).show();
size = "Small";
}
if (checkedId == R.id.rb2) {
Toast.makeText(MainActivity.this, "Medium", Toast.LENGTH_SHORT).show();
size = "Medium";
}
if (checkedId == R.id.rb3) {
Toast.makeText(MainActivity.this, "Large", Toast.LENGTH_SHORT).show();
size = "Large";
}
Intent intent = new Intent(this, Activity2.class);
intent.putExtra("PizzaSize", size);
startActivity(intent);
}
});
and this is your Activity2:
public class Activity2 extends AppCompatActivity {
EditText editName, editPhone, editEmail, editAddress;
TextView total;
Button buttonSubmit;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);
editName = (EditText) findViewById(R.id.editName);
editPhone = (EditText) findViewById(R.id.editPhone);
editEmail = (EditText) findViewById(R.id.editEmail);
editAddress = (EditText) findViewById(R.id.editAddress);
total = (TextView) findViewById(R.id.total);
buttonSubmit = (Button) findViewById(R.id.button2);
// you can here get your Intent after initializing the views
String size = getIntent().getStringExtra("PizzaSize");
buttonSubmit.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
String name = editName.getText().toString();
String phone = editPhone.getText().toString();
String email = editEmail.getText().toString();
String address = editAddress.getText().toString();
total.setText("Name:\t" + name + "\nPhone:\t" + phone +"\nEmail:\t" + email + "\nAddress:\t" + address);
}
});
}
}

App crashes at the second start, wont keep the key in memory

public String SavedPassword;
#Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_log_in);
Button btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Random rnd = new Random();
int n = 1000 + rnd.nextInt(9000);
String str = "";
str = Integer.toString(n);
SavedPassword = str;
String pass = str.toString();
TextView tv1 = (TextView) findViewById(R.id.tv1);
tv1.setText(pass);
Button btn2 = (Button) findViewById(R.id.btn2);
}
});
Button btn2 = (Button) findViewById(R.id.btn2);
btn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String pass = SavedPassword;
TextView tv2 = (TextView) findViewById(R.id.tv2);
EditText edt = (EditText) findViewById(R.id.edt);
String passc = edt.getText().toString();
if (pass.equals(passc)) {
Intent intent = new Intent(getApplicationContext(), Photos.class);
startActivity(intent);
} else {
tv2.setText("TRY AGAIN!");
}
}
});
}
So, I want the first button btn1 to make a key, and store it, after that I want the button to be disabled , button 2 (btn2) should be the LogIn one, and it should compare if the key is equal with the password you enter in EditText, if so, should send you to Photos.class, does that the first time when you run the app, (without the disable part because I dont know how to implement it yet) but the second time I open the app and put the "key" as password it will crash the app, I doesnt store the key in memory...
How can I fix this without using a database?
Here is a very basic guide you can follow: https://www.journaldev.com/9412/android-shared-preferences-example-tutorial
I added some code below that should help you I think. You'll have to double check if the syntax is all good, I didn't run it anywhere.
Basically I have it checking shared preferences first, to see if you have any passwords saved. If you don't, I disable the second button. If you do, I enable the second button. Also SavedPassword gets set to the value.
public String SavedPassword;
#Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_log_in);
Button btn1 = (Button) findViewById(R.id.btn1);
SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); // 0 - for private mode
Editor editor = pref.edit();
SavedPassword = pref.getString("stored_password", null); // getting String
if(SavedPassword == null) {
btn2.setEnabled(false);
} else {
bt2.setEnabled(true);
}
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Random rnd = new Random();
int n = 1000 + rnd.nextInt(9000);
String str = "";
str = Integer.toString(n);
SavedPassword = str;
editor.putString("stored_password", SavedPassword).commit(); // Storing string
String pass = str.toString();
TextView tv1 = (TextView) findViewById(R.id.tv1);
tv1.setText(pass);
Button btn2 = (Button) findViewById(R.id.btn2);
}
});
Button btn2 = (Button) findViewById(R.id.btn2);
btn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String pass = SavedPassword;
TextView tv2 = (TextView) findViewById(R.id.tv2);
EditText edt = (EditText) findViewById(R.id.edt);
String passc = edt.getText().toString();
if (pass.equals(passc)) {
Intent intent = new Intent(getApplicationContext(), Photos.class);
startActivity(intent);
} else {
tv2.setText("TRY AGAIN!");
}
}
});
}

Opening next Activity

I have have a problem here with my code. I want to open the next Activity using submit button but I'm having issues. Can anybody help me on the mistake I am making so that I can implement it? Thanks
public class Chairperson extends Activity implements View.OnClickListener{
TextView textView;
Button submit_btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chairperson);
submit_btn = (Button) findViewById(R.id.submit_btn);
submit_btn.setOnClickListener(this);
textView = (TextView) findViewById(R.id.welcome_txt);
String message = getIntent().getStringExtra("message");
textView.setText(message);
Button submit_btn = (Button) findViewById(R.id.submit_btn);
final TextView submitTextView = (TextView) findViewById(R.id.submitTextView);
final RadioGroup rg1 = (RadioGroup) findViewById(R.id.rg1);
submit_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Get the checked Radio Button ID from Radio Grou[
int selectedRadioButtonID = rg1.getCheckedRadioButtonId();
// If nothing is selected from Radio Group, then it return -1
if
(selectedRadioButtonID != -1) {
RadioButton selectedRadioButton = (RadioButton) findViewById(selectedRadioButtonID);
String selectedRadioButtonText = selectedRadioButton.getText().toString();
submitTextView.setText(selectedRadioButtonText + " selected.");
} else {
submitTextView.setText("Nothing selected .");
}
}
});
}
#Override
public void onClick(View v) {
startActivity(new Intent(this, ViceChairperson.class));
}
}
I have written a code for your button, delete all previous code for submit_btn in your code and replace with this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addListenerOnButton();
public void addListenerOnButton() {
final Context context = this;
submit_btn = (Button) findViewById(R.id.submit_btn);
submit_btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
if (radioGroup.getCheckedRadioButtonId() == -1)
{
Toast.makeText(context, "Select an option.", Toast.LENGTH_LONG).show();
}
else{
Intent intent = new Intent(context, ViceChairperson.class);
startActivity(intent);
finish();
}
}
});
}
}
If you have any issues please let me know.
Just move the line
startActivity(new Intent(getApplicationContext(), ViceChairperson.class));
after the if (selectedRadioButtonID != -1) check. If that check succeeds you start the new activity, if not, nothing is launched.
There's no need for the second onClick method, which is not bound to anything and will never be invoked.

No output in EditText. Why?

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) {
CheckBox yes = (CheckBox) findViewById(R.id.yes);
CheckBox no = (CheckBox) findViewById(R.id.no);
EditText ageText = (EditText) findViewById(R.id.ageText);
EditText editText = (EditText) findViewById(R.id.editText);
EditText editText3 = (EditText) findViewById(R.id.editText3);
int age;
age = 0;
if (yes.isChecked()) {
editText3.setText(age + 15);
} else if (no.isChecked()) {
editText3.setText(age - 10);
}
finish();
}
});
}
This code is not giving me any output in editText3. Why this is happening? The code has no bugs but still no output!
Change
button.setOnClickListener(new)onClickListener() ...
to
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
boolean checked = ((CheckBox) view).isChecked();
if (checkBox.isChecked()){
editText3.setText(age+15);
} else if (checkBox.isChecked()){
editText3.setText(age - 10);
}
}
});
You wrongly used setOnClickListener. Change your code this way:
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
boolean checked = ((CheckBox) view).isChecked();
if (checkBox.isChecked()) {
//check age is string or not.if not a string means change into String format
editText3.setText(age + 15);
} else if (checkBox.isChecked()) {
editText3.setText(age - 10);
}
}
});

Dialog box content doesnot change according to that row

I am giving one button in all the row,if we click that button dialog box has to appear in that one it has to display the content according to the row.
public void bindView(View view, Context context, final Cursor cursor){
int row_id = cursor.getColumnIndex("_id"); //Your row id (might need to replace)
TextView tv = (TextView) view.findViewById(R.id.text2);
final TextView tv1 = (TextView) view.findViewById(R.id.text1);
TextView tv2 = (TextView) view.findViewById(R.id.date);
CheckBox cb = (CheckBox) view.findViewById(R.id.checkbox);
int col1 = cursor.getColumnIndex("expname");
final String expname = cursor.getString(col1 );
int col2 = cursor.getColumnIndex("expcontent");
final String expcontent = cursor.getString(col2 );
int col3 = cursor.getColumnIndex("expdate");
final String expdate = cursor.getString(col3);
cb.setTag(cursor.getPosition());
cb.setChecked(mCheckStates.get(cursor.getPosition(), false));
cb.setOnCheckedChangeListener(this);
// TextView tv2 = (TextView) view.findViewById(R.id.text3);
//cursor.getColumnName(1)
tv.setText( expname);
tv1.setText( expcontent);
tv2.setText(expdate);
//tv2.setText( ""+cursor.getColumnIndex(GinfyDbAdapter.CATEGORY_COLUMN_COUNT));
// String[] from = new String[]{GinfyDbAdapter.CATEGORY_COLUMN_TITLE, GinfyDbAdapter.CATEGORY_COLUMN_CONTENT, GinfyDbAdapter.CATEGORY_COLUMN_COUNT}
ImageButton button = (ImageButton) view.findViewById(R.id.sms);
button.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
StringBuffer sb2 = new StringBuffer();
sb2.append("Title:");
sb2.append(Html.fromHtml(expname));
sb2.append(",Content:");
sb2.append(Html.fromHtml(expcontent));
sb2.append("\n");
String strContactList1 = (sb2.toString().trim());
sendsmsdata(strContactList1);
}
});
ImageButton button1 = (ImageButton) view.findViewById(R.id.mail);
button1.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
StringBuffer sb3 = new StringBuffer();
sb3.append("Title:");
sb3.append(Html.fromHtml(expname));
sb3.append(",Content:");
sb3.append(Html.fromHtml(expcontent));
sb3.append("\n");
String strContactList2 = (sb3.toString().trim());
sendmaildata(strContactList2);
}
});
ImageButton button2 = (ImageButton) view.findViewById(R.id.btnaudioprayer);
button2.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
//ADD STUFF HERE you know which row is clicked. and which button
typed = expcontent;
speakOut();
}
});
ImageButton button3 = (ImageButton) view.findViewById(R.id.bBlame);
button3.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
//ADD STUFF HERE you know which row is clicked. and which button
dialog.show();
}
});
dialog=new Dialog(ExperiencesActivity.this);
dialog.setContentView(R.layout.exp1);
dialog.setCancelable(true);
dialog.setTitle("My Experiences");
textview1 = (TextView)dialog.findViewById(R.id.tv11);
textview1.setText("Title:" + expname);
textview2 = (TextView)dialog.findViewById(R.id.tv22);
textview2.setText("Content:" + expcontent);
Button button23=(Button)dialog.findViewById(R.id.btnSubmit);
button23.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
But here my problem is it will not take the respective content in dialog box,whenever we click the first item in an button,it will shows the content in all the row of button click. Dialog box content has to change according to the row.
You need to create saperate classe for your textviews. Like
private class ViewHolder {
TextView textview1;
TextView textview2;
Button button23;
}
Update your dialog like...
public void showMyDialog(){
dialog=new Dialog(ExperiencesActivity.this);
ViewHolder viewholder;
dialog.setContentView(R.layout.exp1);
dialog.setCancelable(true);
dialog.setTitle("My Experiences");
ViewHolder.textview1 = (TextView)dialog.findViewById(R.id.tv11);
ViewHolder.textview1.setText("Title:" + expname);
ViewHolder.textview2 = (TextView)dialog.findViewById(R.id.tv22);
ViewHolder.textview2.setText("Content:" + expcontent);
ViewHolder.button23=(Button)dialog.findViewById(R.id.btnSubmit);
ViewHolder.button23.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
And call showMyDialog() method onclick of button.
ImageButton button3 = (ImageButton) view.findViewById(R.id.bBlame);
button3.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
//ADD STUFF HERE you know which row is clicked. and which button
showMyDialog();
}
});

Categories

Resources