i want get image from the listview .But problem is that whatever the list view i created that is not clickable. i tried with onItemclick listener also, but its not working because of listview is not clickable . Its seems that listview is not at all clickable ..Below is given adapter for for listview.
// The adapter of the GridView which contains the details of the detected faces.
private class FaceListAdapter extends BaseAdapter {
//List<FaceRectangle> ffRect;
// The detected faces.
List<Face> faces;
List<UUID> faceIdList;
List<IdentifyResult> mIdentifyResults;
// The thumbnails of detected faces.
List<Bitmap> faceThumbnails;
// Initialize with detection result.
FaceListAdapter(Face[] detectionResult) {
//ffRect=new ArrayList<>();
faceIdList = new ArrayList<>();
faces = new ArrayList<>();
faceThumbnails = new ArrayList<>();
mIdentifyResults = new ArrayList<>();
if (detectionResult != null) {
faces = Arrays.asList(detectionResult);
for (Face face: faces) {
try {
// Crop face thumbnail with five main landmarks drawn from original image.
faceThumbnails.add(ImageHelper.generateFaceThumbnail(mBitmap, face.faceRectangle));
faceRect=face.faceRectangle;
//ffRect.add(faceRect);
faceIdList.add(null);
} catch (IOException e) {
// Show the exception when generating face thumbnail fails.
//setInfo(e.getMessage());
}
}
}
}
public void setIdentificationResult(IdentifyResult[] identifyResults) {
mIdentifyResults = Arrays.asList(identifyResults);
}
#Override
public boolean isEnabled(int position) {
return false;
}
#Override
public int getCount() {
return faces.size();
}
#Override
public Object getItem(int position) {
return faces.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.item_face_with_description, parent, false);
}
convertView.setId(position);
// Show the face thumbnail.
((ImageView)convertView.findViewById(R.id.face_thumbnail)).setImageBitmap(faceThumbnails.get(position));
if (mIdentifyResults.size() == faces.size()) {
// Show the face details.
DecimalFormat formatter = new DecimalFormat("#0.00");
if (mIdentifyResults.get(position).candidates.size() > 0) {
String personId = mIdentifyResults.get(position).candidates.get(0).personId.toString();
String personName = StorageHelper.getPersonName(personId, "person", Face_detection.this);
String identity = "Person: " + personName + "\n" + "Confidence: " + formatter.format(mIdentifyResults.get(position).candidates.get(0).confidence);
((TextView) convertView.findViewById(R.id.text_detected_face)).setText(identity);
photoAdd.setEnabled(false);
} else {
((TextView) convertView.findViewById(R.id.text_detected_face)).setText(
R.string.face_cannot_be_identified);
photoAdd.setEnabled(true);
// btmp.add(faceThumbnails.get(position));
//fRect.add(ffRect.get(position));
}
}
return convertView;
}
}
> item_face_with_description.xml
<!-- Copyright (c) Microsoft. All rights reserved. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/face_thumbnail"
android:layout_width="80dp"
android:layout_height="80dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:id="#+id/text_detected_face" />
</LinearLayout>
Xml that contains ListView
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_face_detection"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="myapptest.techm.com.myapptest.Face_detection">
<include
android:id="#+id/tool_bar"
layout="#layout/tacho_toolbar"></include>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tool_bar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="Take Again"
android:layout_height="wrap_content"
android:layout_marginTop="22dp"
android:id="#+id/takePhoto"
android:layout_below="#+id/camerapreview"
android:layout_centerHorizontal="true"
android:layout_width="150dp"
android:onClick="clickPhoto (Face_detection)"
android:visibility="gone" />
<TextView
android:text="Faces in Image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView23"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:layout_below="#+id/takePhoto"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="42dp" />
<ListView
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_below="#+id/textView23"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="28dp"
android:id="#+id/face_detect_list"
android:focusable="false" />
<Button
android:text="Add"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="25dp"
android:layout_marginStart="25dp"
android:layout_marginBottom="103dp"
android:id="#+id/photoAdd" />
<Button
android:text="Cancle"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/photoAdd"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="66dp"
android:layout_marginEnd="66dp"
android:id="#+id/cancle" />
<SurfaceView
android:id="#+id/camerapreview"
android:layout_width="350dp"
android:layout_height="400dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp" />
<Button
android:text="Identify"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/cancle"
android:layout_alignRight="#+id/takePhoto"
android:layout_alignEnd="#+id/takePhoto"
android:layout_marginRight="18dp"
android:layout_marginEnd="18dp"
android:id="#+id/identify"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
The isEnabled method on your adapter is responsible for your ListView ignoring clicks.
#Override
public boolean isEnabled(int position)
{
return false;
}
Your adapter overrides isEnabled and returns false for all positions, indicating that every item in the list is disabled. Disabled views do not receive input events.
If its possible to disable items in your list then your custom adapter needs to track these items somehow (e.g. a list), otherwise you should be returning true for all positions.
Related
Could someone give me an idea how to begin implementing vertical, non-linear stepper control described in the Android Material Design guide here:
http://www.google.com/design/spec/components/steppers.html
you can check this library , however this is still in development.
just extend the mobileStepperSimple class and implement the methods init,onFinished.
you can add the steppers as fragments by extending the stepperFragment and implement onNextButtonHandler to handle next button click.
check the demo for more usage.
any contributions and optimization will be helpful.
Well not exactly the same but as per my requirement, I developed custom VERTICAL STEPPER.
Below is the source code of whole demo.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"/>
</LinearLayout>
Single Item for List(Design your single item of your stepper in raw.xml file)
raw.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/iv_upper_line"
android:layout_width="wrap_content"
android:layout_height="20dp"
app:srcCompat="#drawable/order_status_line" />
<ImageView
android:id="#+id/iv_circle"
android:layout_width="30dp"
android:layout_height="30dp"
app:srcCompat="#drawable/circle_o" />
<ImageView
android:id="#+id/iv_lower_line"
android:layout_width="wrap_content"
android:layout_height="20dp"
app:srcCompat="#drawable/order_status_line" />
</LinearLayout>
<LinearLayout
android:id="#+id/ly_status"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/tv_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="Order Rcived"
android:layout_gravity="left"
android:textSize="18sp"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/ly_orderstatus_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|top"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageview"
android:layout_width="20dp"
android:layout_height="20dp"
app:srcCompat="#drawable/ic_restore_black" />
<TextView
android:id="#+id/tv_orderstatus_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|top"
android:text="8:30am,Jan 31,2018"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
MainActivity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
orderStatusList();
}
private void orderStatusList() {
ArrayList<OrderStatusModel> arrayOfStatus =OrderStatusModel.getStoreDetail();
OrderStatusAdapter adapter = new OrderStatusAdapter(this, arrayOfStatus);
ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
}
Adapter Class
class OrderStatusAdapter extends ArrayAdapter<OrderStatusModel> {
Context context;
ArrayList<OrderStatusModel> order_status;
boolean isOn = false;
public OrderStatusAdapter(Contextcontext,ArrayList<OrderStatusModel>order_status{super(context, 0, order_status);
this.context = context;
this.order_status = order_status;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// Check if an existing view is being reused, otherwise inflate the view if(convertView==null)convertView=LayoutInflater.from(getContext()).inflate(R.layout.raw,parent,false);
}
// Get the data item for this position
OrderStatusModel order_status_data = getItem(position);
// Lookup view for data population
ImageView iv_upper_line = (ImageView)
convertView.findViewById(R.id.iv_upper_line);
ImageView iv_lower_line =(ImageView)
convertView.findViewById(R.id.iv_lower_line);
final ImageView iv_circle = (ImageView) convertView.findViewById(R.id.iv_circle);
TextView tv_status = (TextView) convertView.findViewById(R.id.tv_status);
TextView tv_orderstatus_time =(TextView)
convertView.findViewById(R.id.tv_orderstatus_time);
LinearLayout ly_orderstatus_time = (LinearLayout)
convertView.findViewById(R.id.ly_orderstatus_time);
LinearLayout ly_status = (LinearLayout) convertView.findViewById(R.id.ly_status);
// Populate the data into the template view using the data object
tv_status.setText(order_status_data.getTv_status());
tv_orderstatus_time.setText(order_status_data.getTv_orderstatus_time());
if(position == 0){
iv_upper_line.setVisibility(View.INVISIBLE);
}
else if (position == order_status.size()-1){
iv_lower_line.setVisibility(View.INVISIBLE);
ly_orderstatus_time.setVisibility(View.GONE);
}
convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
iv_circle.setBackgroundResource(R.drawable.bullseye);
Toast.makeText(context, "You Clicked at
item"position,Toast.LENGTH_SHORT).show();
}
});
// Return the completed view to render on screen
return convertView;
}
}
Model Class
private String tv_status;
private String tv_orderstatus_time;
public OrderStatusModel(String tv_status, String tv_orderstatus_time) {
this.tv_status = tv_status;
this.tv_orderstatus_time = tv_orderstatus_time;
}
public String getTv_status() {
return tv_status;
}
public void setTv_status(String tv_status) {
this.tv_status = tv_status;
}
public String getTv_orderstatus_time() {
return tv_orderstatus_time;
}
public void setTv_orderstatus_time(String tv_orderstatus_time) {
this.tv_orderstatus_time = tv_orderstatus_time;
}
public static ArrayList<OrderStatusModel> getStoreDetail() {
ArrayList<OrderStatusModel> status = new ArrayList<OrderStatusModel>();
status.add(new OrderStatusModel("Order Rcived", "8:30am,Jan 31,2018"));
status.add(new OrderStatusModel("On The Way", "10:30am,Jan 31,2018"));
status.add(new OrderStatusModel("Delivered", "aaaaaa"));
return status;
}
Because no Support Library solution exists (still) I have tried several of these libraries in a recent project. My favourite (for appearance, smoothness and functionality) was This Project by "ernestoyaquello". I also added some options to it on My Fork.
The only thing to note with this, is that it does not use an 'adapter' class but instead uses a callback interface.
Demo Screen from Git:
frist my english skill weak.
description>
this is list view.
ㅡㅡㅡㅡㅡㅡㅡㅡ
ㅣㅡㅡㅡㅡㅡㅣㅢ <-- this is button , i init set invisible
ㅣㅡㅡㅡㅡㅡㅣㅢ
ㅣㅡㅡㅡㅡㅡㅣㅢ
ㅣㅡㅡㅡㅡㅡㅣㅢ
ㅣㅡㅡㅡㅡㅡ ////// <-- i want make visible button
ㅣㅡㅡㅡㅡㅡ ////// <-- specific position
I make the custom ListView
ListView row contains texts, Button.
The Button is set invisible option in xml file.
then, I want set the visible specific row button.
I tried that and failed
after make ArrayList for ListView, marking matching position like this
for(i=0; i<arraylist.size(); i++){
int t41=Integer.parseInt(arraylist.get(i).getm());
if(month == t41){
confirm_replay[i]=true;
temp55=i;
}
}
I can set the textValue. through adapter.getItem(int position).
but i don't know, how to control specific button.
also try add button into adapter. failed..
also search question in google but my eng skill bad. failed
add my code.
main.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">
<TextView
android:paddingTop="10dp"
android:text="match day(weekend)"
android:textSize="28dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:background="#2d000000"
android:layout_width="match_parent"
android:layout_height="3dp">
</LinearLayout>
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
list.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">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/m"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:paddingLeft="10dp"
android:id="#+id/d"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/yoil"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/time"
android:textSize="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/vsTeam"
android:textSize="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/league"
android:paddingLeft="10dp"
android:textSize="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/공갈"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button_youtube"
android:text="다시보기"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"/>
</LinearLayout>
</LinearLayout>
<?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">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/m"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:paddingLeft="10dp"
android:id="#+id/d"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/yoil"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/time"
android:textSize="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/vsTeam"
android:textSize="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/league"
android:paddingLeft="10dp"
android:textSize="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/공갈"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button_youtube"
android:text="다시보기"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"/>
</LinearLayout>
</LinearLayout>
</b>
adapter
class MlistViewAdapter extends BaseAdapter {
// Declare Variables
Context mContext;
LayoutInflater inflater;
private List<MatchInfomation> matchinformationlist = null;
private ArrayList<MatchInfomation> arraylist;
public MlistViewAdapter(Context context,
List<MatchInfomation> matchinformationlist) {
mContext = context;
this.matchinformationlist = matchinformationlist;
inflater = LayoutInflater.from(mContext);
this.arraylist = new ArrayList<MatchInfomation>();
this.arraylist.addAll(matchinformationlist);
}
public class ViewHolder {
TextView m;
TextView d;
TextView yoil;
TextView vsTeam;
TextView time;
TextView league;
}
#Override
public int getCount() {
return matchinformationlist.size();
}
#Override
public MatchInfomation getItem(int position) {
return matchinformationlist.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.activity_match_list, null);
button_youtube.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setPackage("com.google.android.youtube");
intent.putExtra("query", "Android");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
});
// Locate the TextViews in listview_item.xml
holder.m = (TextView) view.findViewById(R.id.m);
holder.d = (TextView) view.findViewById(R.id.d);
holder.yoil = (TextView) view.findViewById(R.id.yoil);
holder.vsTeam = (TextView) view.findViewById(R.id.vsTeam);
holder.time = (TextView) view.findViewById(R.id.time);
holder.league = (TextView) view.findViewById(R.id.league);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
// Set the results into TextViews
holder.m.setText(matchinformationlist.get(position).getm());
holder.d.setText(matchinformationlist.get(position).getd());
holder.yoil.setText(matchinformationlist.get(position).getyoil());
holder.vsTeam.setText(matchinformationlist.get(position).getvsTeam());
holder.time.setText(matchinformationlist.get(position).gettime());
holder.league.setText(matchinformationlist.get(position).getleague());
return view;
}
}
If you want to adjust a specific row, you can use the position parameter in your getView() method in adapter. For instance;
if(position==55){
holder.m.setVisibility(View.GONE);
}
I'm not sure i understand your question.
If i'm right you juste want your button to be invisble for specific row. To do so add the specific line at the end of your getView method
yourButton.setVisibility(View.INVISIBLE)
If you want to hide the entire row, the best way will probably be to change your adapter to diplay only row with content.
before setting the values to the view check the condition whatever you want like:-
if condition is true then set your view visible
else set your view invisible
if(true){
button.setVisibility(View.VISIBLE);
}else{
button.setVisibility(View.GONE);
}
In the Android app I'm developing I'm loading a list of several items for the user to input some data; there's a checkbox and an EditText for each item, and the user can check the checkbox and type some notes regarding the item. This list is loaded dynamically from a local database, which in turn is populated from a remote database at a previous point. Now, the problem I'm having is that, whenever I focus on an EditText, after I lose focus on the element, the list seems to load again (elements which where unchecked/blank originally and had been checked/had text typed in them become unchecked/blank again, and those which were checked/had text initially go back to the original state). This only happens when I lose focus on the EditText; I can check and uncheck the checkboxes and they stay how I leave them (until I get and lose focus on an EditText). How can I avoid this so my elements retain the data?
I've tested the app in deviced with Android versions 3.2 and 4.2
Any help would be appreciated.
Here's the activity that loads the list:
public class PostventaPreentregaDetalleActivity extends Activity implements OnItemClickListener, OnItemSelectedListener {
private ArrayList<EncuestaPostventa> listaChequeoEncuesta;
private ArrayList<ConsumoBien> listaConsumoBien;
private ListView lvChequeoEncuesta;
private ListView lvConsumoBien;
private EncuestaPostventaAdapter adapter;
private ConsumoBienAdapter adapterConsumoBien;
public static DBProvider oDB;
#Override
public void onBackPressed() {
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.postventa_preentrega_detalle_activity_actions, menu);
return true;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
getActionBar().setDisplayHomeAsUpEnabled(true);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_postventa_preentrega_detalle);
listaChequeoEncuesta = new ArrayList<EncuestaPostventa>();
listaConsumoBien = new ArrayList<ConsumoBien>();
inicializarPestanas();
cargarDetalleNegocio();
listarChequeoEncuesta();
listarConsumoBien();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public void onItemClick(AdapterView<?> adapter, View view, int position,
long ID) {
}
public void cargarDetalleNegocio(){
Intent intent = getIntent();
TextView tvProyecto;
TextView tvCliente;
TextView tvRut;
TextView tvDireccion;
tvProyecto = (TextView) findViewById(R.id.tvProyecto);
tvRut = (TextView) findViewById(R.id.tvRut);
tvCliente = (TextView) findViewById(R.id.tvCliente);
tvDireccion = (TextView) findViewById(R.id.tvDireccion);
tvProyecto.setText(intent.getStringExtra("proyecto").trim());
tvRut.setText(intent.getStringExtra("rut").trim());
tvCliente.setText(intent.getStringExtra("cliente").trim());
tvDireccion.setText(intent.getStringExtra("direccion").trim());
}
public void inicializarPestanas(){
TabHost tabs = (TabHost)findViewById(android.R.id.tabhost);
tabs.setup();
TabHost.TabSpec spec = tabs.newTabSpec("tabChequeo");
spec.setContent(R.id.tabChequeo);
spec.setIndicator("Chequeo");
tabs.addTab(spec);
spec = tabs.newTabSpec("tabServicios");
spec.setContent(R.id.tabServicios);
spec.setIndicator("Servicios consumidos");
tabs.addTab(spec);
spec = tabs.newTabSpec("tabObservaciones");
spec.setContent(R.id.tabObservaciones);
spec.setIndicator("Observaciones");
tabs.addTab(spec);
tabs.setCurrentTab(0);
}
public void listarChequeoEncuesta(){
try{
oDB = new DBProvider(this);
Intent intent = getIntent();
int idBien = intent.getIntExtra("id_bien", 0);
int idEncuestaPreentrega = intent.getIntExtra("id_encuestapreentrega", 0);
String[][] arrayChequeoEncuesta = oDB.traerEncuestaPostventa(idBien,
idEncuestaPreentrega);
if(!(arrayChequeoEncuesta == null)){
for(int i=0; i<arrayChequeoEncuesta.length; i++){
int idEncuestaPostventa = Integer.parseInt(arrayChequeoEncuesta[i][0]);
int idEncuestaDetalle = Integer.parseInt(arrayChequeoEncuesta[i][1]);
String item = arrayChequeoEncuesta[i][2];
Boolean recepcion = (Integer.parseInt(arrayChequeoEncuesta[i][3]) != 0);
String observacion =arrayChequeoEncuesta[i][4];
listaChequeoEncuesta.add(new EncuestaPostventa(idEncuestaPostventa,
idEncuestaDetalle,
item,
recepcion,
observacion));
}
}
adapter = new EncuestaPostventaAdapter(this, listaChequeoEncuesta);
lvChequeoEncuesta = (ListView) findViewById(R.id.lvChequeoEncuesta);
lvChequeoEncuesta.setAdapter(adapter);
}catch(Exception e){
Toast.makeText(this, "Error (listarChequeoEncuesta): " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
public void listarConsumoBien(){
try{
oDB = new DBProvider(this);
Intent intent = getIntent();
int argIdBien = intent.getIntExtra("id_bien", 0);
int argIdEmpsa = intent.getIntExtra("id_empsa", 0);
String[][] arrayConsumoBien = oDB.traerConsumoBien(argIdBien,
argIdEmpsa);
if(!(arrayConsumoBien == null)){
for(int i=0; i<arrayConsumoBien.length; i++){
int idConsumoBien = Integer.parseInt(arrayConsumoBien[i][0]);
int idBien = Integer.parseInt(arrayConsumoBien[i][1]);
int idDominio = Integer.parseInt(arrayConsumoBien[i][2]);
String nombre = arrayConsumoBien[i][3];
String unidad = arrayConsumoBien[i][4];
int cantidad = Integer.parseInt(arrayConsumoBien[i][5]);
Boolean estado = (Integer.parseInt(arrayConsumoBien[i][6]) != 0);
listaConsumoBien.add(new ConsumoBien(idConsumoBien,
idBien,
idDominio,
nombre,
unidad,
cantidad,
estado));
}
}
adapterConsumoBien = new ConsumoBienAdapter(this, listaConsumoBien);
lvConsumoBien = (ListView) findViewById(R.id.lvConsumoBien);
lvConsumoBien.setAdapter(adapterConsumoBien);
}catch(Exception e){
Toast.makeText(this, "Error (listarConsumoBien): " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
}
public void onNothingSelected(AdapterView<?> parent)
{
}
}
And its layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:parentActivityName="net.gestionwireless.officemovil.inmobiliario.PostventaPreentregaActivity">
<TabHost android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:textSize="#dimen/texto_L"
android:id="#+id/tvLabelProyecto"
android:text="#string/proyecto"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/texto_L"
android:id="#+id/tvProyecto"
android:text=""
android:layout_toRightOf="#id/tvLabelProyecto" />
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:textSize="#dimen/texto_L"
android:id="#+id/tvLabelRut"
android:layout_below="#id/tvLabelProyecto"
android:text="#string/rut"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/texto_L"
android:id="#+id/tvRut"
android:text=""
android:layout_toRightOf="#id/tvLabelRut"
android:layout_below="#id/tvProyecto" />
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:textSize="#dimen/texto_L"
android:id="#+id/tvLabelCliente"
android:layout_marginLeft="50dp"
android:layout_below="#id/tvLabelProyecto"
android:layout_toRightOf="#id/tvRut"
android:text="#string/cliente" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/texto_L"
android:id="#+id/tvCliente"
android:text=""
android:layout_toRightOf="#id/tvLabelCliente"
android:layout_below="#id/tvProyecto" />
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:textSize="#dimen/texto_L"
android:id="#+id/tvLabelDireccion"
android:layout_below="#id/tvCliente"
android:text="#string/direccion"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/texto_L"
android:id="#+id/tvDireccion"
android:text=""
android:layout_toRightOf="#id/tvLabelDireccion"
android:layout_below="#id/tvCliente" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/tvDireccion">
<TabWidget android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#android:id/tabs" />
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#android:id/tabcontent">
<LinearLayout
android:id="#+id/tabChequeo"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">
<TextView
android:text="#string/titulo_grilla_item"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".33"
android:gravity="center"
android:textSize="#dimen/titulo_grilla"
android:textStyle="bold" />
<TextView
android:text="#string/titulo_grilla_recepcion"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".1"
android:gravity="center"
android:textSize="#dimen/titulo_grilla"
android:textStyle="bold" />
<TextView
android:text="#string/titulo_grilla_observacion"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".57"
android:gravity="center"
android:textSize="#dimen/titulo_grilla"
android:textStyle="bold" />
</LinearLayout>
<ListView
android:id="#+id/lvChequeoEncuesta"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/tabServicios"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">
<TextView
android:text="#string/titulo_grilla_servicio"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".4"
android:gravity="center"
android:textSize="#dimen/titulo_grilla"
android:textStyle="bold" />
<TextView
android:text="#string/titulo_grilla_recepcion"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".1"
android:gravity="center"
android:textSize="#dimen/titulo_grilla"
android:textStyle="bold" />
<TextView
android:text="#string/titulo_grilla_consumo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:gravity="center"
android:textSize="#dimen/titulo_grilla"
android:textStyle="bold" />
<TextView
android:text="#string/titulo_grilla_unidad"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:gravity="center"
android:textSize="#dimen/titulo_grilla"
android:textStyle="bold" />
</LinearLayout>
<ListView
android:id="#+id/lvConsumoBien"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
</ListView>
</LinearLayout>
<LinearLayout android:id="#+id/tabObservaciones"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="#+id/etObservaciones"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/hint_observaciones" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</RelativeLayout>
</TabHost>
</LinearLayout>
The class for each item:
package net.gestionwireless.officemovil.inmobiliario;
public class EncuestaPostventa {
private int idEncuestaPostventa;
private int idEncuestaDetalle;
private String item;
private Boolean recepcion;
private String observacion;
public EncuestaPostventa(int idEncuestaPostventa,
int idEncuestaDetalle,
String item,
Boolean recepcion,
String observacion) {
this.idEncuestaPostventa = idEncuestaPostventa;
this.idEncuestaDetalle = idEncuestaDetalle;
this.item = item;
this.recepcion = recepcion;
this.observacion = observacion;
}
public int traerIdEncuestaPostventa() {
return idEncuestaPostventa;
}
public void asignarIdEncuestaPostventa(int idEncuestaPostventa) {
this.idEncuestaPostventa = idEncuestaPostventa;
}
public int traerIdEncuestaDetalle() {
return idEncuestaDetalle;
}
public void asignarIdEncuestaDetalle(int idEncuestaDetalle) {
this.idEncuestaDetalle = idEncuestaDetalle;
}
public String traerItem() {
return item;
}
public void asignarItem(String item) {
this.item = item;
}
public Boolean traerRecepcion() {
return recepcion;
}
public void asignarRecepcion(Boolean recepcion) {
this.recepcion = recepcion;
}
public String traerObservacion() {
return observacion;
}
public void asignarObservacion(String observacion) {
this.observacion = observacion;
}
}
package net.gestionwireless.officemovil.inmobiliario;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
The adapter:
public class EncuestaPostventaAdapter extends ArrayAdapter<EncuestaPostventa> {
private Context context;
private ArrayList<EncuestaPostventa> datos;
public EncuestaPostventaAdapter(Context context, ArrayList<EncuestaPostventa> datos) {
super(context, R.layout.encuestapostventa_item, datos);
this.context = context;
this.datos = datos;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View item = LayoutInflater.from(context).inflate(
R.layout.encuestapostventa_item, null);
TextView tvItem = (TextView) item.findViewById(R.id.tvItem);
tvItem.setText(datos.get(position).traerItem());
CheckBox chkRecepcion = (CheckBox) item.findViewById(R.id.chkRecepcion);
chkRecepcion.setChecked(datos.get(position).traerRecepcion());
EditText editObservacion = (EditText) item.findViewById(R.id.editObservacion);
editObservacion.setText(datos.get(position).traerObservacion());
return item;
}
}
And the layout for each item:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="horizontal">
<TextView
android:id="#+id/tvItem"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:textSize="#dimen/texto_L" />
<CheckBox
android:id="#+id/chkRecepcion"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".1"/>
<EditText
android:id="#+id/editObservacion"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".57"
android:textSize="#dimen/texto_L"
android:inputType="textCapSentences" />
</LinearLayout>
If you put a log statement in your ArrayAdapter.getView(), you'll realize what's going on in two seconds.
As the list is scrolled, a list item that you edited is scrolled out of view. When the item is scrolled back into view, the view is recreated and getView() is called. Since your adapter doesn't have a representation of the changes that were made previously, getView() recreates the view with the original unedited data.
If that's happening to you on focus lost, that must mean that the focus-lost event is triggering a view update on the list item. I've never done editing in a list item, so I'm not familiar with that behavior.
You need to put event listeners on your EditText and CheckBox that store their edited state somewhere. Then your adapter needs to use that edit state when creating the list items.
You might have to write a more complex adapter that extends BaseAdapter directly. The adapter is the Model for your list View, and there's no state in a ListView except for your adapter. In the case of ListView, the view can update any part of its list at any time, so the adapter has to have the current model data for the ListView at all times.
I am extending ListFragment to display data retrieved from a web server in an AsyncTask in another class. If I set a custom height (i.e. 400dp) on the #android:id/list widget in my xml, getView() does not get called at all. If I set it to wrap_content, getView() gets called for the list items but the list items don't show up! It seems that the listview does not expand to fit the item heights, even though the list item's xml specifies a layout height. When a fixed height is defined I can see the colored background of the list, but no data. getCount() never returns 0.
Part of the adapter class:
public class gAdapter extends ArrayAdapter<GroupObject> {
ArrayList<GroupObject> groups;
public gAdapter(Context context, int textViewResId, ArrayList<GroupObject> groups) {
super(context, R.layout.groups_listview_row, groups);
mInflater = (LayoutInflater) con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
con = context;
this.groups = groups;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final int pos = position;
View row = convertView;
if(convertView == null)
row = mInflater.inflate(R.layout.groups_listview_row, parent, false);
TextView name = (TextView) row.findViewById(R.id.groups_listview_name);
//Set name
try {
name.setText( groups.get(position).groupName);
Log.d("test", "Got name " + groups.get(position).groupName);
} catch(Exception e) {
e.printStackTrace();
name.setText("Could not load name");
}
return row;
}
#Override
public int getCount() {
Log.d("test", "Returning count " + (this.groups.size() != 0 ? this.groups.size() : 0));
return this.groups.size() != 0 ? this.groups.size() : 0;
}
#Override
public GroupObject getItem(int position) {
Log.d("test", "get item " + position);
return this.groups.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
groups_listview_row.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical" >
<ImageView
android:id="#+id/groups_listview_imageview"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/avatar" />
<RelativeLayout
android:id="#+id/RelativeLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/groups_listview_imageview"
android:layout_alignTop="#+id/groups_listview_imageview"
android:layout_toRightOf="#+id/groups_listview_imageview" >
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/groups_listview_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="0.8"
android:ellipsize="marquee"
android:scrollHorizontally="true"
android:lines="1"
android:marqueeRepeatLimit="marquee_forever"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/groups_listview_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="5dp"
android:gravity="right|bottom"
android:singleLine="true"
android:text="zCode: 000000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#+id/LinearLayout1"
android:layout_gravity="bottom"
android:gravity="bottom" >
<TextView
android:id="#+id/groups_listview_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="10dp"
android:layout_weight="0.8"
android:gravity="left|bottom"
android:text="Location" />
<TextView
android:id="#+id/groups_listview_numMembers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginRight="10dp"
android:layout_weight="0.2"
android:gravity="right|bottom"
android:text="0 Members" />
</LinearLayout>
</RelativeLayout>
I have used a Custom ListView and I am displaying some data using the same ListView. When I click on the List View item, the onClickListener is not getting called. I am not able to select any list item.
Layout Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="16dp"
android:background="#drawable/list_selector"
android:clickable="true"
android:orientation="horizontal"
android:padding="5dip" >
<LinearLayout
android:id="#+id/imgProperty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:padding="3dip" >
<ImageView
android:id="#+id/list_image"
android:layout_width="50dp"
android:layout_height="50dp"
android:contentDescription="#string/app_name"
android:src="#drawable/ic_launcher"
android:focusable="false"/>
</LinearLayout>
<TextView
android:id="#+id/tvCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="75dip"
android:layout_toRightOf="#+id/list_image"
android:paddingBottom="10dip"
android:text="property"
android:textColor="#040404"
android:textSize="15sp"
android:textStyle="bold"
android:typeface="sans" />
<TextView
android:id="#+id/tvprice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imgProperty"
android:layout_alignLeft="#+id/tvCity"
android:text="Price"
android:focusable="false"/>
</RelativeLayout>
Adapter code:
public class CustomListAdapter extends BaseAdapter {
ArrayList<Propety> PropertiesArray;
private LayoutInflater Inflater;
public CustomListAdapter(ArrayList<Propety> PropertiesArray) {
this.PropertiesArray=PropertiesArray;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return PropertiesArray.size();
}
#Override
public Object getItem(int position) {
return PropertiesArray.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, final ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
convertView = inflater.inflate(R.layout.customlistview, parent, false);
}
final Propety ListArray = PropertiesArray.get(position);
TextView tvPropertyName = (TextView) convertView.findViewById(R.id.tvCity);
tvPropertyName.setText(ListArray.getName());
TextView tvPrice = (TextView) convertView.findViewById(R.id.tvprice);
tvPrice.setText(ListArray.getPrice());
ImageView imgProperty = (ImageView) convertView.findViewById(R.id.list_image);
imgProperty.setImageResource(R.drawable.ic_launcher);
convertView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(parent.getContext(), "view clicked: " + ListArray.getName(), Toast.LENGTH_SHORT).show();
}
});
return convertView;
}
}
ListView code:
ListView propertylistview = (ListView) findViewById(R.id.listview);
CustomListAdapter customlistview=new CustomListAdapter(PropertiesArray);
propertylistview.setAdapter(customlistview);
ListView XML:
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/customview"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="24dp"
android:background="#drawable/list_selector"
android:textAlignment="center" >
custom.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<SurfaceView
android:id="#+id/surface"
android:layout_width="fill_parent"
android:layout_height="match_parent" />
<TextView
android:id="#+id/txtangle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="115dp"
android:layout_marginLeft="95dp"
android:text="" />
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/customview"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="24dp"
android:background="#drawable/list_selector"
android:textAlignment="center" >
</ListView>
<view
android:id="#+id/customview"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
class="com.example.samplebuapp.CustomCompass" />
<view
android:id="#+id/view1"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_above="#+id/listview"
android:layout_alignParentRight="true"
android:layout_marginRight="18dp"
class="com.example.samplebuapp.CustomView" />
<LinearLayout
android:id="#+id/rl1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/listview"
android:orientation="vertical"
android:focusable="false">
</LinearLayout>
</RelativeLayout>
Even scrolling is not working.
I am unable to figure out why is this happening? Am I missing out something?
Any help in resolving this is appreciated.
The following will do the job in your case.
ListView propertylistview = (ListView) findViewById(R.id.listview);
propertylistview.setOnItemClickListener( myListViewClicked ):
OnItemClickListener myListViewClicked = new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(YourActivity.this, "Clicked at positon = " + position, Toast.LENGTH_SHORT).show();
}
};
Dont forget to remove the following from the CustomAdapter
convertView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(parent.getContext(), "view clicked: " + ListArray.getName(), Toast.LENGTH_SHORT).show();
}
});
If the touch events are getting intercepted inside the cell layout, in the layout for your custom cell, set
android:descendantFocusability="blocksDescendants" on the top level layout of your cell. For me, it was too much of a pain to add xml attributes to every individual view.
Note that this can also be set in code:
cell.setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);
I also tried this with a ListView inside a cell, and I had to override onTouchEvent to get it to work:
public class NoTouchListView extends ListView {
#Override
public boolean onTouchEvent(MotionEvent ev) {
return false;
}
}
the simple code that solved my problem, and method view.setOnClickListener be within my custom adapter
view.setFocusable(false)
Check your list row layout once :
layout or any view should not be `android:clickable="true" and
android:focusable="true"
if it is there just delete and run the application again.
Even I was having the same problem, I am having checkbox, did the following to masker itemClickListener work,
Added the following properties to the checkbox,
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
and ItemClickListner started working.
For detailed example you can go through the link,
http://knowledge-cess.com/android-itemclicklistner-with-checkbox-or-radiobutton/
Hope it helps Cheers!!
For TextView you should also use
android:textIsSelectable="false"
https://developer.android.com/reference/android/widget/TextView.html#setTextIsSelectable