Hi,
in a custom ArrayAdapter i don't see onItemClick firing. I would like
to pack all the logic in there so i need access to the views in each
row of the adapter (2 Buttons,1 EditText). I was looking on the
internet for hours to find a real howto.
Q1: Is there a tutorial on the net?
Q2: Do you see a bug/whats missing?
Q3: How to seduce a clicked View in onItemClick?
Any help is really really appreciated,
lf.hl
----------This is the activity-----------
package org.rice;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import android.os.Bundle;
import java.util.*;
import android.widget.AdapterView.OnItemClickListener;
import android.util.*;
public class AdapterTest extends Activity{
private ArrayList<FuItem> fItems;
private ArrayAdapter<FuItem> aa;
private ListView myListView;
private void fillit(){
fItems = new ArrayList<FuItem>();
for(int i = 0; i < 5; i++){
FuItem fi = new FuItem(String.valueOf(i), (float)i);
fItems.add(fi);
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myListView = (ListView)findViewById(R.id.liste);
fillit();
int resId = R.layout.row;
aa = new FuItemAdapter(this, resId, fItems);
myListView.setAdapter(aa);
myListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
myListView.setItemsCanFocus(true);
myListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2,
long arg3) {
// TODO Auto-generated method stub
Log.i("adaptertest", "onItemClick fired");
}
});
}
}
-------------Custom Adapter FuItemAdapter---------------
package org.rice;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;
import android.content.Context;
import java.util.*;
import android.util.*;
import android.widget.Button;
public class FuItemAdapter extends ArrayAdapter<FuItem> {
int resource;
public FuItemAdapter(Context _context, int _resource, List<FuItem>
_items) {
super(_context, _resource, _items);
resource = _resource;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LinearLayout fuitemView;
FuItem item = getItem(position);
String productString = item.getProduct();
String priceString = String.valueOf(item.getPrice());
if(convertView == null){
fuitemView = new LinearLayout(getContext());
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater vi;
vi =
(LayoutInflater)getContext().getSystemService(inflater);
vi.inflate(resource, fuitemView, true);
}
else {
fuitemView = (LinearLayout) convertView;
}
TextView productView = (TextView)fuitemView.findViewById
(R.id.product);
EditText priceView =
(EditText)fuitemView.findViewById(R.id.price);
Button down = (Button)fuitemView.findViewById(R.id.down);
Button up = (Button)fuitemView.findViewById(R.id.up);
down.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.i(getClass().getSimpleName(),"button onclick
fired:" );
}
});
up.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.i(getClass().getSimpleName(),"button onclick
fired");
}
});
priceView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.i(getClass().getSimpleName(),"button
onclick fired");
}
});
priceView.setFocusable(true);
down.setFocusable(true);
productView.setText(productString);
priceView.setText(priceString);
return fuitemView;
}
public boolean areAllItemsSelectable() {
return true;
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---