I'm trying to create a app where you can add strings to a list from another activity, but every time i add a new string to the list it replaces the old one.
How can I fix this?
Code where the list is.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_list);
Button button = (Button) findViewById(R.id.addBtn);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(ShowList.this, AddToList.class));
}
});
Intent i = getIntent();
Bundle b = i.getExtras();
if(b!=null) {
String textToList = b.getString("listText");
List<String> stuff = new ArrayList<String>();
final ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, stuff);
ListView list = (ListView) findViewById(R.id.listView);
list.setAdapter(adapter);
adapter.add(textToList);
adapter.notifyDataSetChanged();
}
}
the xml files code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".ShowList">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"
android:id="#+id/addBtn"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="List:"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_centerHorizontal="true"
android:layout_above="#+id/addBtn"
android:layout_below="#+id/textView" />
Code for the file where you input text:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_to_list);
final Bundle b = new Bundle();
final Intent i = new Intent(AddToList.this, ShowList.class);
final EditText text = (EditText)this.findViewById(R.id.listText);
Button btn = (Button) findViewById(R.id.btnAdd);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String s = text.getText().toString();
b.putString("listText", s);
i.putExtras(b);
startActivity(i);
}
});
}
And finally the xml code for the previous peace of code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.mathias.listapp.AddToList">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listText"
android:layout_alignParentTop="true"
android:layout_marginTop="100dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:inputType="text"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADD"
android:id="#+id/btnAdd"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
This happens because you are creating a new List everytime you enter in your activity. So the field in which you save your list has to be a "permanent" one. I recommend you to declare a static list and check if it's not null:
Code where your list is:
public class Nameofmyclass{
static List<String> stuff;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_list);
if(stuff==null){
stuff = new ArrayList<String>();
}
ListView list = (ListView) findViewById(R.id.listView);
Button button = (Button) findViewById(R.id.addBtn);
final ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, stuff);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(ShowList.this, AddToList.class));
}
});
Intent i = getIntent();
Bundle b = i.getExtras();
if(b!=null) {
String textToList = b.getString("listText");
stuff.add(textToList);
}
list.setAdapter(adapter);
}
}
By the way there are several "problems" in your code:
You added the item to the adapter, not to the list
You initialized your listview only if your bundle isn't null, why? Your listview will remain everytime, you don't need to initialize it with this check
You created a final intent in your other class outside the click. This isn't programmatically wrong, but there isn't any motivation in this case for which you need to do it. It's better do it locally inside the click as you did in the first class
try this ,
String textToList = b.getString("listText");
List<String> stuff = new ArrayList<String>();
stuff.add(textToList)
final ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, stuff);
ListView list = (ListView) findViewById(R.id.listView);
list.setAdapter(adapter);
adapter.notifyDataSetChanged();
Related
To assign data of an ArrayList<String> alKategorien to a spinner auswahl_kategorie, I am using this snippet:
ad = new ArrayAdapter(
this,
android.R.layout.simple_spinner_item,
alKategorien);
ad.setDropDownViewResource(
android.R.layout
.simple_spinner_dropdown_item);
auswahl_kategorie.setAdapter(ad);
I tried to reuse the ArrayAdapter by phrasing it like
if (ad == null) {
ad = new ArrayAdapter(
this,
android.R.layout.simple_spinner_item,
alKategorien);
ad.setDropDownViewResource(
android.R.layout
.simple_spinner_dropdown_item);
auswahl_kategorie.setAdapter(ad);
}
else
{
ad.clear();
ad.addAll(alKategorien);
ad.notifyDataSetChanged();
}
Yet unless ad is null, this yields an empty spinner.
How do I reuse the ArrayAdapter properly?
I have just made a very simple sample.
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
tools:context=".MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 1"
android:id="#+id/bt1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 2"
android:id="#+id/bt2" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 3"
android:id="#+id/bt3" />
<Button
android:id="#+id/btGetSpinnersValues"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Get Spinners Values" />
</LinearLayout>
item_schreiben.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<TextView
android:id="#+id/tvSample"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Spinner
android:layout_marginBottom="20dp"
android:layout_width="match_parent"
android:layout_height="70dp"
android:id="#+id/auswahl_kategorie" />
</LinearLayout>`
MainActivity.java:
public class MainActivity extends AppCompatActivity {
private final int NO_OF_ITEMS = 3;
Button bt1, bt2, bt3, btGetSpinnersValues;
//Spinner auswahl_kategorie;
ArrayList<String> alKategorien = new ArrayList();
ArrayList<Integer> alDynamicChildren = new ArrayList();
ArrayAdapter ad;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout rootLayout = findViewById(R.id.rootLayout);
bt1 = findViewById(R.id.bt1);
bt2 = findViewById(R.id.bt2);
bt3 = findViewById(R.id.bt3);
btGetSpinnersValues = findViewById(R.id.btGetSpinnersValues);
alKategorien.add("a");
alKategorien.add("b");
alKategorien.add("c");
alKategorien.add("d");
alKategorien.add("e");
setSpinnerAdapter();
for (int i = 0; i < NO_OF_ITEMS; i++) {
View dl_item_schreiben = getLayoutInflater().inflate(R.layout.item_schreiben, null);
rootLayout.addView(dl_item_schreiben);
alDynamicChildren.add(rootLayout.indexOfChild(dl_item_schreiben));
TextView textView = dl_item_schreiben.findViewById(R.id.tvSample);
textView.setText("Spinner " + (i + 1));
Spinner auswahl_kategorie = dl_item_schreiben.findViewById(R.id.auswahl_kategorie);
auswahl_kategorie.setAdapter(ad);
auswahl_kategorie.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
}
#Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
bt1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
alKategorien.clear();
alKategorien.add("A");
alKategorien.add("B");
alKategorien.add("C");
alKategorien.add("D");
alKategorien.add("E");
ad.notifyDataSetChanged();// or setSpinnerAdapter();
}
});
bt2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
alKategorien.clear();
alKategorien.add("1");
alKategorien.add("2");
alKategorien.add("3");
alKategorien.add("4");
alKategorien.add("5");
ad.notifyDataSetChanged();// or setSpinnerAdapter();
}
});
bt3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
alKategorien = new ArrayList<>();
alKategorien.add("A");
alKategorien.add("B");
alKategorien.add("C");
alKategorien.add("D");
alKategorien.add("E");
setSpinnerAdapter();
}
});
btGetSpinnersValues.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String msg = "";
LinearLayout parent = (LinearLayout) view.getParent();
for (int i = 0; i < NO_OF_ITEMS; i++) {
Spinner auswahl_kategorie = parent.getChildAt(alDynamicChildren.get(i)).findViewById(R.id.auswahl_kategorie);
msg += "Spinner " + (i +1) + ": " + auswahl_kategorie.getSelectedItem().toString() + "\n";
}
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}
});
}
private void setSpinnerAdapter() {
if (ad == null) {
ad = new ArrayAdapter(this, android.R.layout.simple_spinner_item, alKategorien);
ad.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//auswahl_kategorie.setAdapter(ad);
} else {
//ad.clear();
//ad.addAll(alKategorien);
ad.notifyDataSetChanged();
}
}
}
I tested the code and spinner changed content for bt1/bt2 clicked. But after bt3 clicked, no more change.
First, when the adapter is created, it is set with alKategorien as the data list, so call ad.clear() just clear alKategorien and ad.addAll(alKategorien); add back an empty list. Therefore those two lines should be removed.
Second, data list cannot be created again (i.e. = new ArrayList<>() and so no more change after bt3 clicked) but can be modified (clear, add, remove) because it acts like a linkage between activity and adapter. If data list is created again by new, then the adapter needs to be created again as linkage broken. There may be other conditions that can break the linkage. Since the code that I mentioned in first point is removed, so issue should be caused by the way of modifying data list which is not shown in the snippet.
I want to display text input from an editText and show it in a listView using an ArrayAdapter, when clicking a button, the listView does gets an item added but without the text :
here is the code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.blink.blink.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="61dp">
<EditText
android:layout_width="280dp"
android:layout_height="60dp"
android:hint="Type a quote .. "
android:id="#+id/quoteField" />
<Button
android:layout_width="wrap_content"
android:layout_height="60dp"
android:text="Add Quote"
android:id="#+id/addQuote"
android:fontFamily="sans-serif-condensed"
android:background="#f6546a"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/quoteField" />
</RelativeLayout>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/quotelistView"
android:foreground="#f6546a"/>
</LinearLayout>
and :
public class MainActivity extends AppCompatActivity {
Button createBtn ;
EditText quoteField;
ListView quotesListView;
ArrayList<String> quotesArrayList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createBtn = (Button) findViewById(R.id.addQuote);
quoteField = (EditText) findViewById(R.id.quoteField);
quotesListView = (ListView) findViewById(R.id.quotelistView);
quotesArrayList = new ArrayList<>();
createBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
quotesArrayList.add(quoteField.getText().toString());
SetAdapter();
quoteField.setText(" ");
}
});
}
private void SetAdapter()
{
ArrayAdapter<String> Adapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, quotesArrayList);
quotesListView.setAdapter(Adapter);
}
}
You do not need to reset the adapter everytime you change the data in the array. What you should do is keep a reference to the adapter and call adapter.notifyDataSetChanged() when you change the data in the list
public class MainActivity extends AppCompatActivity {
Button createBtn ;
EditText quoteField;
ListView quotesListView;
ArrayList<String> quotesArrayList;
ArrayAdapter<String> adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createBtn = (Button) findViewById(R.id.addQuote);
quoteField = (EditText) findViewById(R.id.quoteField);
quotesListView = (ListView) findViewById(R.id.quotelistView);
quotesArrayList = new ArrayList<>();
adapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, quotesArrayList);
quotesListView.setAdapter(adapter);
createBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
quotesArrayList.add(quoteField.getText().toString());
adapter.notifyDataSetChanged();
quoteField.setText(" ");
}
});
}
}
Try it!
createBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
quotesArrayList.add(quoteField.getText().toString());
SetAdapter(quotesArrayList);
quoteField.setText(" ");
}
});
}
private void SetAdapter(ArrayList<String> quotesArrayList)
{
ArrayAdapter<String> Adapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, quotesArrayList);
quotesListView.setAdapter(Adapter);
Adapter.notifyDataSetChanged();
}
I have ListView in which in each row it has a textview and a delete button. The values for the list is from the sqlite database. I have successfully populate list from the database. My problem is that i do not know how to correctly implement the onClickItemListener for the textview and delete button. What i want is that when i click the textview, it will go another intent (based on its specific id from the database). And if i click the delete button, it will delete the item.
This is my code:
ListView listView ;
ArrayList<String> list;
public int goal_id;
int i = 0;
//database variables
MyDBAdapter dbhandler;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_act);
TypefaceProvider.registerDefaultIconSets();
Bundle extras = getIntent().getExtras();
if (extras == null) {
return;
}
goal_id = Integer.parseInt(extras.getString("goalid"));
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setSubtitle("Activities List");
ActionBar actionBar = getSupportActionBar();
actionBar.setHomeAsUpIndicator(R.drawable.ic_back);
actionBar.setDisplayHomeAsUpEnabled(true);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Added new activity", Snackbar.LENGTH_LONG)
.setAction("Added new activity", null).show();
onCLick_addAct();
}
});
dbhandler = new MyDBAdapter(this);
populateListView();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Long temp = listView.getItemIdAtPosition(position);
MessageTo.message(SetActActivity.this, Long.toString(temp));
}
});
}
public void populateListView(){
Cursor cursor = dbhandler.getAllActivitiesByGoalCursor(goal_id);
String[] actlist = new String[] {dbhandler.dbhandler.COLUMN_ACTIVITY_NAME};
int[] actNames = new int[] {R.id.list_item_string};
SimpleCursorAdapter myAdapter = new SimpleCursorAdapter(SetActActivity.this,R.layout.act_list,cursor,actlist,actNames,0);
//handle listview and assign adapter
listView = (ListView)findViewById(R.id.list);
// Attach cursor adapter to the ListView
listView.setAdapter(myAdapter);
}
public void onCLick_addAct(){
i++;
//to create activities
final Activities act = new Activities(goal_id,"Activity " + i, 0,1,1,1,0, false,0,0,0,0);
long temp = dbhandler.createActivity(act);
String temp2 = Long.toString(temp);
final int act_id = Integer.parseInt(temp2);
populateListView();
}
act_list.xml
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:descendantFocusability="blocksDescendants">
<TextView
android:clickable="false"
android:focusable="false"
android:id="#+id/list_item_string"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:paddingLeft="15dp"
android:textSize="18sp"
android:textStyle="bold"
android:layout_row="0"
android:layout_column="0"
android:paddingRight="30dp" />
<Button
android:clickable="false"
android:focusable="false"
android:id="#+id/delete_btn"
android:layout_width="40dp"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:layout_row="0"
android:layout_column="1"
android:background="#drawable/ic_delete" />
</GridLayout>
https://stackoverflow.com/a/7047141
See this post.
Xml also has onclick property. So try using it.
Can anyone please tell me how to fix the below code? I am trying to setonclick listner and its causing null exception
ArrayList<Contact> imageArry = new ArrayList<Contact>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adapter = new ContactImageAdapter1(this, R.layout.screen_list1,
imageArry);
ListView dataList = (ListView) findViewById(R.id.list);
dataList.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// Send intent to SingleViewActivity
Intent i = new Intent(MainActivity.this, SingleViewActivity.class);
// Pass image index
i.putExtra("id", position);
startActivity(i);
} });
Edit
--
When I click on the image its not sending me to another activity
this my activity_main.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="Latest" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:background="#B29090" >
</ListView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:gravity="center_vertical"
android:text="Recomanded" />
<ListView
android:id="#+id/list1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:background="#4A9C67" >
</ListView>
</LinearLayout>
</ScrollView>
Your variable listView where you want to add a listener seems not initialized
Your listView is dataList not listView
You should write :
dataList.setOnItemClickListener(...)
Set onClickListener() to your ListView variable datalist. You're currently setting it to listView which exists no where else in your code.
ListView dataList = (ListView) findViewById(R.id.list);
dataList.setAdapter(adapter);
dataList.setOnItemClickListener(new OnItemClickListener() {...}
Change your code to this :
ArrayList<Contact> imageArry = new ArrayList<Contact>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adapter = new ContactImageAdapter1(this, R.layout.screen_list1,
imageArry);
ListView dataList = (ListView) findViewById(R.id.list);
dataList.setAdapter(adapter);
dataList .setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// Send intent to SingleViewActivity
Intent i = new Intent(MainActivity.this, SingleViewActivity.class);
// Pass image index
i.putExtra("id", position);
startActivity(i);
} });
Your code were fine, the problem what you have faced is this listview is NULL because listview it's not declared, I guess you misstyped the ListView, you only have to change listview to dataList.
i am working in android .where i created one list view and each row of list view contain two edit text fields and two buttons ,now i want on set onclicklistener on the button,but i am getting error.so can you help on this...
installation.java
setContentView(R.layout.activity_installation);
Datalist=(ListView)findViewById(R.id.installationList);
ButtonLayout ViewButton=new ButtonLayout();
ArrayList<HashMap<String, String>> arl = (ArrayList<HashMap<String, String>>) getIntent().getSerializableExtra("hashMap");
SimpleAdapter adapter = new SimpleAdapter(
Installation.this, arl,
R.layout.activity_button_layout, new String[]
{
TAG_Title,TAG_URL
}, new int[] {
R.id.InnerText1,R.id.URL1 });
Datalist.setAdapter(adapter);
ViewButton.ClickButton = (ImageButton)activity_button_layout.findViewById(R.id.ImageButton011);
ViewButton.ClickButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View view) {
Log.i("Edit Button Clicked", "*********");
}
});
i am getting error that activity_button_layout cannot be resolved.when i am using it ViewButton.ClickButton = (ImageButton)activity_button_layout.findViewById(R.id.ImageButton011);
activity_button_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="#+id/widget36"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/listbackground"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ImageButton
android:id="#+id/widget37"
android:layout_width="46dp"
android:layout_height="48dp"
android:layout_x="275dp"
android:layout_y="5dp"
android:src="#drawable/download"
/>
<TextView
android:id="#+id/InnerText1"
android:layout_width="265dp"
android:layout_height="wrap_content"
android:layout_x="8dp"
android:layout_y="9dp"
android:background="#07000000"
android:text=" "
android:textColor="#ffffff"
android:textSize="14sp" />
<ImageButton
android:id="#+id/ImageButton011"
android:layout_width="46dp"
android:layout_height="48dp"
android:layout_x="315dp"
android:layout_y="5dp"
android:clickable="true"
android:onClick="clickImage"
android:src="#drawable/viewdoc" />
<TextView
android:id="#+id/URL1"
android:layout_width="241dp"
android:layout_height="wrap_content"
android:layout_x="6dp"
android:layout_y="38dp"
android:textColor="#ff5d5d5d"
android:textStyle="bold" />
</AbsoluteLayout>
ButtonLayout.java
private static final String TAG_InnerText = "InnerText";
private static final String TAG_Title = "Title";
private static final String TAG_URL = "URL";
public ImageButton ClickButton=null;
EditText EditURL=null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_button_layout);
}
use this in your adapter
ViewButton.ClickButton = (ImageButton)activity_button_layout.findViewById(R.id.ImageButton011);
ViewButton.ClickButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View view) {
Log.i("Edit Button Clicked", "*********");
}
});
R.layout.activity_button_layout is an ID of a resource defined in R.xml, not a reference to a created view of any kind, so trying to use activity_button_layout as such will have little sense.
Instead, you should override the getView() method from your SimpleAdapter, and after inflating a single list item, attach the onClickListener to the desired subview.
try this,
ImageButton imageButton = (ImageButton) findViewById(R.id.ImageButton011);
imageButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Log.i("Edit Button Clicked", "*********");
}
});