I am trying pass data from my dialog box to a new Activity. So basically what i want to do for example in my Dialog box i have Name: John, when i click on my okay button it opens a new activity but i want that John to be set in my edit box on my new activity:
Here is my Activity where my Dialog box code is:
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/** To change selected state view */
view.setSelected(true);
HashMap<String, Object> obj = (HashMap<String, Object>) ADAhere.getItem(position);
String SlectedName = (String) obj.get("NAME");
String SlectedPrice = (String) obj.get("PRICE");
String SlectedSize = (String) obj.get("SIZE");
String SlectedRange = (String) obj.get("RANGE");
String SlectedSupp = (String) obj.get("SUPPLIER");
// Toast.makeText(getActivity().getApplicationContext(), SlectedName, Toast.LENGTH_SHORT).show();
final Dialog dialog = new Dialog(getActivity());
dialog.getWindow();
//dialog.setTitle("Confirm your Vote");
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.diaglog);
final TextView VName = (TextView) dialog.findViewById(R.id.Name);
final TextView VRange = (TextView) dialog.findViewById(R.id.Range);
final TextView VSUPPLIER = (TextView) dialog.findViewById(R.id.Supplier);
final TextView VSIZE = (TextView) dialog.findViewById(R.id.Size);
final TextView VPrice = (TextView) dialog.findViewById(R.id.Price);
VName.setText(SlectedName);
VRange.setText(SlectedRange);
VSUPPLIER.setText(SlectedSupp);
VSIZE.setText(SlectedSize);
VPrice.setText(SlectedPrice);
dialog.show();
Button cancelBtn = (Button) dialog.findViewById(R.id.cancel_btn);
cancelBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
Button UpdateBtn = (Button) dialog.findViewById(R.id.btn_update);
UpdateBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(getActivity().getApplicationContext(),Upvalence.class);
startActivity(i);
}
});
Button deleteBtn = (Button) dialog.findViewById(R.id.btn_delete);
deleteBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(getActivity().getApplicationContext(),Upvalence.class);
startActivity(i);
}
});
dialog.show();
}
});
so i want to pass VName.setText(SlectedName); to a new activity:
name1.setText(dialogactivityname);
Pass in as an extra:
instead of:
Intent i = new Intent(getActivity().getApplicationContext(),Upvalence.class);
startActivity(i);
you should pass in the name
Intent i = new Intent(getActivity().getApplicationContext(),Upvalence.class);
i.putExtra("string", SlectedName);
startActivity(i);
Then, on your Upvalence activity:
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
Bundle arguments = this.getIntent().getExtras();
String yourString = arguments.getString("string");
}
Related
i am in a pickle at the moment to how to approach making 3 buttons within a single dialog box make the option selected change the text of the button used to show the dialog box, so far only managed to get option3 to work as i suppose its the last intent so the only button that works would be the button for option3
here is the code im trying to pass to the main button from the dialog
public class LabelDialog extends AppCompatDialogFragment {
private Button option1, option2, option3;
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.label_dialog, null);
builder.setView(view);
//option 1 and 2
option3 = view.findViewById(R.id.label_lecturebtn);
option3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String option3 = "Lecture";
Intent intent3 = new Intent(getContext(), AddTask.class);
intent3.putExtra("lecture", option3);
startActivity(intent3);
dismiss();
}
});
and the main code
protected void onCreate(Bundle savedInstanceState) {
//...
label_button = findViewById(R.id.button_labels);
label_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openDialog();
}
});
checkLabelResult();
}
public void openDialog() { //Labels dialog
//code to open dialog
}
public void checkLabelResult() {
//intents 1 and 2, same format as 3 but keys changed accordingly
Intent intent3 = getIntent();
String option3 = intent3.getStringExtra("lecture");
label_button.setText(option3);
}
Code for Option 1
option1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String option1 = "Important";
Intent intent = new Intent(getContext(), AddTask.class);
intent.putExtra("important", option1);
startActivity(intent);
dismiss();
}
Code for Option 2
option2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String option2 = "To Do";
Intent intent2 = new Intent(getContext(), AddTask.class);
intent2.putExtra("to do", option2);
startActivity(intent2);
dismiss();
}
I have a modal(dialog) with a edit text inside and a send button, what i'm trying to do is simply send the content inside the edit text when the button is clicked, the thing is, sending the content is working, but when i call mydialog.dismiss(); it doesn't work. It is using an instance of another class to call a method retrofit, and inside the "done" and "not done" buttons i have the "enviar"(send) button which is the one i'm trying to close the modal with.
Here is the adapter code:
public TasksAdapter(#NonNull Context context, #SuppressLint("SupportAnnotationUsage") #LayoutRes ArrayList<Tasks> list){
super(context, 0, list);
sContext = context;
taskData = list;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent){
View listItem = convertView;
if(listItem == null)
listItem = LayoutInflater.from(sContext).inflate(R.layout.item_tasks, parent,false);
final Tasks presenteTask = taskData.get(position);
TextView taskTitle = (TextView) listItem.findViewById(R.id.tasksTitle);
taskTitle.setText(presenteTask.getTitle());
EditText taskColor = (EditText) listItem.findViewById(R.id.taskColor);
if(presenteTask.getHexaColor().isEmpty()){
HexaColor = "#FFFFFF";
}
else{
HexaColor = presenteTask.getHexaColor();
taskColor.setBackgroundColor(Color.parseColor(HexaColor));
}
TextView taskTime = (TextView) listItem.findViewById(R.id.taskTime);
taskTime.setText(presenteTask.getTimeStart().toString().substring(0,5));
tasksModal = new Dialog(sContext);
tasksModal.setCancelable(false);
tasksModal.setContentView(R.layout.modal_tasksdone);
tasksModal.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
final EditText comentarios = (EditText) tasksModal.findViewById(R.id.edtComentario);
final Calendario calendario = new Calendario();
Button done = (Button) listItem.findViewById(R.id.tasksDone);
done.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
yorn = true;
tarefaId = presenteTask.getTaskId();
data = presenteTask.getDataTask();
hora = String.valueOf(presenteTask.getTimeStart());
tasksModal.findViewById(R.id.btnSend).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
comentario = comentarios.getText().toString();
if(comentario.equals("")){
Toast.makeText(sContext,"Por favor digite um comentário.", Toast.LENGTH_SHORT).show();
tasksModal.dismiss();
}
else{
calendario.retrofitDoneTasks(tarefaId, comentario, data, hora, yorn, tarefaRealizadaId);
tasksModal.dismiss();
}
}
});
tasksModal.show();
}
});
Button notDone = (Button) listItem.findViewById(R.id.tasksNotDone);
notDone.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
yorn = false;
tarefaId = presenteTask.getTaskId();
data = presenteTask.getDataTask();
hora = String.valueOf(presenteTask.getTimeStart());
tasksModal.findViewById(R.id.btnSend).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
comentario = comentarios.getEditableText().toString();
if(comentario.equals("")){
Toast.makeText(sContext,"Por favor digite um comentário.", Toast.LENGTH_SHORT).show();
tasksModal.dismiss();
}
else{
calendario.retrofitDoneTasks(tarefaId, comentario, data, hora, yorn, tarefaRealizadaId);
tasksModal.dismiss();
}
}
});
tasksModal.show();
}
});
return listItem;
}
}
Thank you very much!
Firstly you have to make your dialog un-cancelable, so that outside click doesn't dismiss it using tasksModal.setCancelable(false);
Secondly no need to repeat code to create dialog inside done/undone button click. So, remove it and move it to TasksAdapter constructor.
Thirdly You are not dismissing your dialog inside done button click. So, add this tasksModal.dismiss();
Check and try with below code:
EditText comentarios;
Calendario calendario;
public TasksAdapter(#NonNull Context context, #SuppressLint("SupportAnnotationUsage") #LayoutRes ArrayList<Tasks> list){
super(context, 0, list);
sContext = context;
taskData = list;
tasksModal = new Dialog(sContext);
tasksModal.setCancelable(false); //make it un cancelable
tasksModal.setContentView(R.layout.modal_tasksdone);
tasksModal.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
comentarios = (EditText) tasksModal.findViewById(R.id.edtComentario);
calendario = new Calendario();
}
-------------------------------------------------------------
Button done = (Button) listItem.findViewById(R.id.tasksDone);
done.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
comentarios.setText("");
yorn = true;
tarefaId = presenteTask.getTaskId();
data = presenteTask.getDataTask();
hora = String.valueOf(presenteTask.getTimeStart());
tasksModal.findViewById(R.id.btnSend).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
comentario = comentarios.getEditableText().toString();
if(!comentario.equals("")){
tasksModal.dismiss(); //dismiss here
calendario.retrofitDoneTasks(tarefaId, comentario, data, hora, yorn, tarefaRealizadaId);
}
else{
Toast.makeText(sContext,"Por favor digite um comentário.", Toast.LENGTH_SHORT).show();
}
}
});
tasksModal.show();
}
});
Button notDone = (Button) listItem.findViewById(R.id.tasksNotDone);
notDone.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
comentarios.setText("");
yorn = false;
tarefaId = presenteTask.getTaskId();
data = presenteTask.getDataTask();
hora = String.valueOf(presenteTask.getTimeStart());
tasksModal.findViewById(R.id.btnSend).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
comentario = comentarios.getEditableText().toString();
if(comentario.equals("")){
Toast.makeText(sContext,"Por favor digite um comentário.", Toast.LENGTH_SHORT).show();
}
else{
tasksModal.dismiss();
calendario.retrofitDoneTasks(tarefaId, comentario, data, hora, yorn, tarefaRealizadaId);
}
}
});
tasksModal.show();
}
});
I am trying to pass an array list to another activity but it seems that is not enough. I searched all day to pass the array list with "intent" but with no success. I wrote a code for learning purposes. How to pass the data and show the Arraylist in a second activity?
The action button is btn_save. If you want further details let me know.
The code is in
MainActivity (first activity):
public class MainActivity extends AppCompatActivity {
ArrayList<String> addArray = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText editTextOne = (EditText) findViewById(R.id.editTextOne);
final EditText editTextTwo = (EditText) findViewById(R.id.editTextTwo);
Button btn_showText = (Button) findViewById(R.id.buttonShow);
final TextView textView = (TextView) findViewById(R.id.textResults);
Button btn_refresh = (Button) findViewById(R.id.btn_refresh);
Button btn_close = (Button) findViewById(R.id.btn_close);
Button btn_save = (Button) findViewById(R.id.btn_save);
final ListView showMe = (ListView) findViewById(R.id.list_items);
btn_showText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String text = editTextOne.getText().toString();
String textTwo = editTextTwo.getText().toString();
if (text.length() == 0 || textTwo.length() == 0){
textView.setText("You must enter Name & Surname");
}else {
textView.setText(Html.fromHtml(
"<font color=\"red\">"+ text + "</font> " +
"<font color=\"blue\"><b>" + textTwo + " </b></font>"));
}
}
});
btn_refresh.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
startActivity(getIntent());
}
});
btn_close.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
System.exit(0);
}
});
btn_save.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Context context = getApplicationContext();
// CharSequence mytext = "Hahahaha";
// int duration = Toast.LENGTH_SHORT;
// Toast toast = Toast.makeText(context,mytext,duration);
// toast.show();
String text = editTextOne.getText().toString();
String textTwo = editTextTwo.getText().toString();
String getInput = text + textTwo;
if (addArray.contains(getInput)){
Toast.makeText(getBaseContext(), "Item already Added!", Toast.LENGTH_LONG).show();
}
else if (getInput == null || getInput.trim().equals("")){
Toast.makeText(getBaseContext(), "Input field is empty", Toast.LENGTH_LONG).show();
}
else{
addArray.add(getInput);
ArrayAdapter<String> adapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, addArray);
showMe.setAdapter(adapter);
Intent intent = new Intent(MainActivity.this, ListOfNames.class);
((EditText)findViewById(R.id.editTextOne)).setText(" ");
((EditText)findViewById(R.id.editTextTwo)).setText(" ");
}
}
});
}
public void onButtonClick(View v){
if (v.getId() == R.id.btn_list){
Intent i = new Intent(MainActivity.this, ListOfNames.class);
startActivity(i);
}
}
}
ListOfNames second activity: (almost empty)
public class ListOfNames extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_screen);
}
}
If you are trying to pass a arraylist of string then it will be easy. Just pass arraylist with intent like this:
ArrayList<String> list = new ArrayList<String>();
Intent intent = new Intent(ActivityOne.this, ActivityTwo.class);
intent.putStringArrayListExtra("key", list);
startActivity(intent);
And receive it in ActivityTwo like this:
ArrayList<String> list = getIntent().getStringArrayListExtra("key");
I found a temporary solution for this (The app is not broke). The only problem is the arraylist didn't increased. It contains and show only the last value.
Main Activity:
...
else{
// addArray.add(getInput);
// ArrayAdapter<String> adapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, addArray);
// showMe.setAdapter(adapter);
Intent intent = new Intent(MainActivity.this, ListOfNames.class);
intent.putExtra("data", getInput);
startActivity(intent);
// ((EditText)findViewById(R.id.editTextOne)).setText(" ");
// ((EditText)findViewById(R.id.editTextTwo)).setText(" ");
}
...
ListOfNames (Second Activity):
public class ListOfNames extends Activity {
ArrayList<String> addArrayT = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_screen);
Bundle bundle = getIntent().getExtras();
String data = bundle.getString("data");
Button btn_more = (Button) findViewById(R.id.btn_more);
ListView showMe = (ListView) findViewById(R.id.list_items);
addArrayT.add(data);
ArrayAdapter<String> adapterT = new ArrayAdapter<>(ListOfNames.this, android.R.layout.simple_list_item_1, addArrayT);
showMe.setAdapter(adapterT);
}
public void onClickMore(View v){
if (v.getId() == R.id.btn_more){
Intent i = new Intent(ListOfNames.this, MainActivity.class);
startActivity(i);
}
}
}
I'm fairly new
I have succeeded to display my search results in my listview using an EditText.
Now when I click my result to bring up the "details" it gives me a wrong database record. The question is how to get the record of the clickedItem from my searchresults.
This is the List.java
public class List extends ActionBarActivity {
DatabaseManager db;
java.util.List<Passwords> passwordLijst = new ArrayList<Passwords>();
java.util.List<String> passwordsTitelLijst = new ArrayList<String>();
EditText inputSearch;
ListView listView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
SwipeRefreshLayout mSwipe = (SwipeRefreshLayout) findViewById(R.id.activity_main_swipe_refresh_layout);
ImageView imageView=new ImageView(this);
imageView.setImageResource(R.drawable.ic_add_white_24dp);
FloatingActionButton actionButton = new FloatingActionButton.Builder(this)
.setContentView(imageView)
.setBackgroundDrawable(R.drawable.selecter_button)
.build();
actionButton.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), addPass.class);
startActivity(intent);
}
}
);
mSwipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
setRefreshListener();
}
});
initDatabaseManager();
}
private void setRefreshListener() {
construeerPasswordLijsten();
constueerScherm();
SwipeRefreshLayout mSwipe = (SwipeRefreshLayout) findViewById(R.id.activity_main_swipe_refresh_layout);
mSwipe.setRefreshing(false);
}
#Override
protected void onResume(){
super.onResume();
construeerPasswordLijsten();
constueerScherm();
}
private void construeerPasswordLijsten(){
passwordLijst = db.getAllPassword();
passwordsTitelLijst = Passwords.constructTitleList(passwordLijst);
}
private void constueerScherm(){
final ListView myListView = (ListView) findViewById(R.id.mylist);
ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(),R.layout.rowlist, passwordsTitelLijst);
myListView.setAdapter(adapter);
myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
int index = position;
Passwords clickedItem = passwordLijst.get(index);
Intent detailIntent = new Intent(getApplicationContext(), ListDetail.class);
detailIntent.putExtra("clickedItem", clickedItem);
startActivity(detailIntent);
}
});
inputSearch = (EditText) findViewById(R.id.inputSearch);
inputSearch.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
#Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
ArrayList<String> temp = new ArrayList<String>();
int textlength = inputSearch.getText().length();
temp.clear();
for (int i = 0; i < passwordsTitelLijst.size(); i++) {
if (textlength <= passwordsTitelLijst.get(i).length()) {
if (inputSearch.getText().toString().equalsIgnoreCase(
(String)
passwordsTitelLijst.get(i).subSequence(0,
textlength))) {
temp.add(passwordsTitelLijst.get(i));
}
}
}
myListView.setAdapter(new ArrayAdapter<String>(List.this, R.layout.rowlist, temp));
myListView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
#Override
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
int index = position;
Passwords clickedItem = passwordLijst.get(index);
Intent intent1 = new Intent(List.this, ListDetail.class);
intent1.putExtra("clickedItem", clickedItem);
startActivity(intent1);
}
});
}
#Override
public void afterTextChanged(Editable arg0) {
}
});
}
Here is the ListDetail.java
public class ListDetail extends ActionBarActivity {
EditText showPW;
CheckBox mcbPW;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_detail);
initialise();
setEditButtonListener();
setSaveButtonListener();
setDeleteButtonListener();
showPW = (EditText) findViewById(R.id.text_detail_pw);
mcbPW = (CheckBox) findViewById(R.id.cbPW);
mcbPW.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (!isChecked) {
showPW.setTransformationMethod(PasswordTransformationMethod.getInstance());
} else {
showPW.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}
}
});
}
private void setDeleteButtonListener() {
Button deleteBtn = (Button) findViewById(R.id.delete_detail_button);
deleteBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = getIntent();
Passwords clickedItem = (Passwords) i.getSerializableExtra("clickedItem");
DatabaseManager db = DatabaseManager.getInstance();
db.deletePasswords(clickedItem);
Toast toast = Toast.makeText(getApplicationContext(), "Password Deleted!", Toast.LENGTH_SHORT);
toast.show();
Intent j = new Intent(getApplicationContext(),List.class);
startActivity(j);
}
});
}
private void setEditButtonListener() {
Button editBtn = (Button) findViewById(R.id.update_detail_button);
editBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
EditText txtView_title = (EditText) findViewById(R.id.text_detail_title);
txtView_title.setEnabled(true);
EditText txtView_user = (EditText) findViewById(R.id.text_detail_username);
txtView_user.setEnabled(true);
EditText txtView_pw = (EditText) findViewById(R.id.text_detail_pw);
txtView_pw.setEnabled(true);
EditText txtView_notes = (EditText) findViewById(R.id.text_detail_notes);
txtView_notes.setEnabled(true);
EditText txtView_url = (EditText) findViewById(R.id.text_detail_url);
txtView_url.setEnabled(true);
EditText txtView_expDate = (EditText) findViewById(R.id.text_detail_expDate);
txtView_expDate.setEnabled(true);
}
});
}
private void setSaveButtonListener() {
Button saveButton = (Button) findViewById(R.id.save_detail_button);
saveButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = getIntent();
Passwords clickedItem = (Passwords)intent.getSerializableExtra("clickedItem");
EditText txtView_title = (EditText) findViewById(R.id.text_detail_title);
String title = txtView_title.getText().toString();
EditText txtView_user = (EditText) findViewById(R.id.text_detail_username);
String user = txtView_user.getText().toString();
EditText txtView_pw = (EditText) findViewById(R.id.text_detail_pw);
String pw = txtView_pw.getText().toString();
EditText txtView_notes = (EditText) findViewById(R.id.text_detail_notes);
String notes = txtView_notes.getText().toString();
EditText txtView_url = (EditText) findViewById(R.id.text_detail_url);
String url = txtView_url.getText().toString();
EditText txtView_expD = (EditText) findViewById(R.id.text_detail_expDate);
String expD = txtView_expD.getText().toString();
Passwords aangepastePW = new Passwords();
aangepastePW.setId(clickedItem.getId());
aangepastePW.setTitle(title);
aangepastePW.setUsername(user);
aangepastePW.setPassword(pw);
aangepastePW.setNotities(notes);
aangepastePW.setUrl(url);
aangepastePW.setExpDate(expD);
DatabaseManager db = DatabaseManager.getInstance();
db.updateStudent(aangepastePW);
Toast.makeText(ListDetail.this, "Information Changed!", Toast.LENGTH_SHORT).show();
Intent j = new Intent(getApplicationContext(),List.class);
startActivity(j);
}
});
}
private void initialise() {
Intent intent = this.getIntent();
Passwords clickedItem = (Passwords)intent.getSerializableExtra("clickedItem");
EditText txtView_title = (EditText) findViewById(R.id.text_detail_title);
txtView_title.setText(clickedItem.getTitle());
txtView_title.setEnabled(false);
EditText txtView_username = (EditText) findViewById(R.id.text_detail_username);
txtView_username.setText(clickedItem.getUsername());
txtView_username.setEnabled(false);
EditText txtView_pw = (EditText) findViewById(R.id.text_detail_pw);
txtView_pw.setText(clickedItem.getPassword());
txtView_pw.setEnabled(false);
EditText txtView_notes = (EditText) findViewById(R.id.text_detail_notes);
txtView_notes.setText(clickedItem.getNotities());
txtView_notes.setEnabled(false);
EditText txtView_url = (EditText) findViewById(R.id.text_detail_url);
txtView_url.setText(clickedItem.getUrl());
txtView_url.setEnabled(false);
EditText txtView_expD = (EditText) findViewById(R.id.text_detail_expDate);
txtView_expD.setText(clickedItem.getExpDate());
txtView_expD.setEnabled(false);
}
In the onItemClick of your listview replace the below line
Passwords clickedItem = passwordLijst.get(index);
with
Passwords clickedItem = adapter.getItem(index);
it retrieves the item at the given position in the adapter.
I need to creat a linearLayout containing some views when clicking on a button , thsi button is triggerd by an action made in another activity ,so i used a performClick , but it seems that doesn't work ; here is my code :
Button click = new Button(rootView.getContext());
SharedPreferences participant;
Editor editor;
SharedPreferences visible;
Editor vis;
participant = rootView.getContext().getSharedPreferences("participant", rootView.getContext().MODE_PRIVATE);
visible = rootView.getContext().getSharedPreferences("visible", rootView.getContext().MODE_PRIVATE);
editor = participant.edit();
final String name= participant.getString("key", "toto");
final String view = participant.getString("view","non");
if(view.equalsIgnoreCase("yes")) click.performClick();
click.setOnClickListener(new OnClickListener() {
#Override
public void onClick(final View v) {
// Creating a new LinearLayout
final LinearLayout ln = new LinearLayout(v.getContext());
// Setting the orientation to horizontal
ln.setOrientation(LinearLayout.HORIZONTAL);
formbis.addView(ln);
TextView tv1 = new TextView(v.getContext());
tv1.setText(name);
tv1.setTextSize(14);
tv1.setTypeface(null, Typeface.BOLD);
tv1.setPadding(0, 15, 0, 10);
tv1.setLayoutParams(new LayoutParams(
500,
LayoutParams.WRAP_CONTENT));
ln.addView(tv1);
final ImageButton edit = new ImageButton(v.getContext());
Drawable checked = getResources().getDrawable( R.drawable.content_edit );
edit.setImageDrawable(checked);
edit.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
edit.setBackgroundColor(Color.WHITE);
edit.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
i = new Intent(v.getContext(), EditParticipantActivity.class);
startActivity(i);
}
});
ln.addView(edit);
final ImageButton delete = new ImageButton(v.getContext());
Drawable deleted = getResources().getDrawable( R.drawable.content_discard );
delete.setImageDrawable(deleted);
delete.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
delete.setBackgroundColor(Color.WHITE);
delete.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Toast.makeText(v.getContext(),
"Deleted ", Toast.LENGTH_LONG).show();
formbis.removeView(ln);
}
});
ln.addView(delete);
ln.setVisibility(View.GONE);
if(view.equalsIgnoreCase("yes"))ln.setVisibility(View.VISIBLE);
}
});
EDIT
Here (another Activity ) I set the value to yes so that the linearLayout gets added to the view of the first activity
Button members = (Button) findViewById(R.id.submit);
members.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
name = firstname.getText().toString();
editor.putString("key", name);
editor.commit();
editor.putString("view", "yes");
editor.commit();
i = new Intent(v.getContext(), ManageActivity.class);
startActivity(i);
//finish();
}
});
Define the onClickListener first.
Then call the if(view.equalsIgnoreCase("yes")) click.performClick(); line after defining the click.onClickListner code.