Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLITE #13

Open
ryanmunene79 opened this issue Aug 24, 2016 · 2 comments
Open

SQLITE #13

ryanmunene79 opened this issue Aug 24, 2016 · 2 comments

Comments

@ryanmunene79
Copy link

how would you use the custom adapter if you are fetching data from the db for the first textview and instead of the second textview,you use an edittext which should set data to the db

@ishtdeephora
Copy link

Hi @ryanmunene79 . For this case, you can use the combination of ArrayAdapter and DialogFragment. List down the first TextView using the array adapter. To edit the particular item in the list, you can add item.onClickListener and open a Dialog to show the editText with a prefilled setText to the item. Once you change the editText, the changes can be maintained at the db level.

Because when you define your custom layout you will add an editText in your case, which may have only one ID and if you target this editText, the changes will always go for the first item in the list but not the corresponding TextView.

@ChinmaySahu1357
Copy link

1 .Create a Custom Adapter Class:
Create a new Java/Kotlin class that extends ArrayAdapter or BaseAdapter
public class CustomAdapter extends ArrayAdapter {
// Constructor and methods
}
2. getView Method:
public View getView(int position, View convertView, ViewGroup parent) {
// Inflate your layout for each item
View view = LayoutInflater.from(getContext()).inflate(R.layout.item_layout, parent, false);

// Get references to your TextView and EditText
TextView textView = view.findViewById(R.id.text_view);
EditText editText = view.findViewById(R.id.edit_text);

// Get the data for this position
YourDataType data = getItem(position);

// Set data to the TextView
textView.setText(data.getText()); // Assuming 'getText()' is a method in YourDataType

// Set data to the EditText
editText.setText(data.getEditTextValue()); // Assuming 'getEditTextValue()' is a method in YourDataType

return view;

}
3. Create your Layout : XML
4. Use the Custom Adapter in Your Activity:
CustomAdapter adapter = new CustomAdapter(this, R.layout.item_layout, yourDataList);
ListView listView = findViewById(R.id.list_view); // Assuming you have a ListView with this id
listView.setAdapter(adapter);
5. Handle EditText Changes:
6. Update the DataBase:
on textChange method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants