setOnItemLongClickListener not receiving events - android

I've got this problem that I cannot receive this event, something is blocking it from one of my items in the listView but I don't know what, I checked focus on the item set to false and it not worked. Also check setting the item to be onlongclickable but it didn't work also. What more?

I had a problem with that and set the parent of the layout android:descendantFocusability="blocksDescendants", this is the list view item layout

you can do something like this in your ListView Adapter ,getView() ,
// For onlongclicks
final View deleteView = convertView;
deleteView.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(final View v) {
// TODO Auto-generated method stub
}
});
//For Just onClick
deleteView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});

Related

i want to get position in a list data how to get the position of click of button in android

how to get the position from list on click of data.
i want access button in android.on the click of button of the adapter class it should give the position.
holder.beginDate.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
you can set the position as the tag
holder.beginDate.setTag(position); // set every time getting the View
and retrieve it using
// put this code where creating a new instance of holder
holder.beginDate.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
int pos = (Integer) view.getTag();
// do anything using the position
}
});
After initialization of your button in getView() method write:
holder.beginDate.setTag(position);
and in your onClick() use:
holder.beginDate.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
int position=Integer.parseInt(((Button)v).getTag().toString());
}
});

Can you help me with a listener?

I have a function of showDiaglog.
I just want to, when user tap checkbox the diaglog shown, and the spinner also, but I got a problem with listener. Everytime I open settings, the popup show up twice.
First because of listener of spinner then second because one of my setting checked.
I save every changes in that setting.
Can you help me?
selectLanguage
.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0,
View arg1, int position, long arg3) {
// TODO Auto-generated method stub
saveSettingan(Key_Select, position);
if (position == 0) {
setDefaultLocal();
} else {
setLocal("in");
}
showDialog();
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
and this one
case R.id.checkAcak:
saveSettingan(Key_Acak, isChecked);
showDialog();
break;
You could store a boolean which remembers the visibility of the dialog. Your show dialog should include this:
if (isDialogVisible)
return;
isDialogVisible = true;
Then you set a dismiss listener to set isDialogVisible to false.

How to add edittext and checkbox into listview android?

I have a problem, when edit-text is setted enable as false. I want to set the edit-text enable as true when the user check the check box in list view but it's not working properly
In the getView method of the customadapter add these lines:
holder.cb.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(holder.cb.isChecked())
{
//enable edit text
}
else
{
//disable edit text
}
}
});

Delete a LinearLayout on long press event

I am creating a LinearLayout dynamically. I need to delete the LinearLayout on LongPress event.
My code :
public void addTileView(View v) {
_parentLayout = (LinearLayout) findViewById(R.id.gridCont);
View child = getLayoutInflater().inflate(R.layout.customtileview,null);
((TextView)child.findViewById(R.id.tileText)).setText("Tile View :"+_tileViewCount++);
_parentLayout.addView(child);
_parentLayout.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Delete", Toast.LENGTH_SHORT).show();
return true;
}
});
}
How to do this ?
try this,
_parentLayout.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Delete", Toast.LENGTH_SHORT).show();
parentLayout.removeAllViews();
return true;
}
});
Its better to remove the view which you added in the parent .
Say Parent layout is the main layout and child layout is the one which you want to remove.
You should try
parent_layout.removeView(child_layout);
removeAllViews() - will remove all the views inside the view , but not the main view .
Please refer to ViewGroup
ViewGroup vg = (ViewGroup)(myView.getParent());
vg.removeView(myView);
Alternatively , You can make the visibility of your view to Visible.GONE , and then make it visible when required.
This works for me.
public void addTileView(View v) {
_parentLayout = (LinearLayout) findViewById(R.id.gridCont);
child = getLayoutInflater().inflate(R.layout.customtileview,null);
((TextView)child.findViewById(R.id.tileText)).setText("Tile View :"+_tileViewCount++);
_parentLayout.addView(child);
child.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Delete", Toast.LENGTH_SHORT).show();
_parentLayout.removeView(v);
return true;
}
});
}
Thanks

How two build two line of text and one image in one item?

i am using java android .
i have a problem in my app and i need some code that can make my item has two lines of texts and one image .
please save me and help .
here is the code for what i tried please make sure that you can help and give your opinion and how i can solve it cause i stucked here.
the main activity
private void setUpView() {
// TODO Auto-generated method stub
etInput = (EditText)this.findViewById(R.id.editText_input);
Pinput = (EditText)this.findViewById(R.id.editText1);
btnAdd = (Button)this.findViewById(R.id.button_add);
lvItem = (ListView)this.findViewById(R.id.listView_items);
itemArrey = new ArrayList<String>();
itemAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,itemArrey);
lvItem.setAdapter(itemAdapter);
btnAdd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
addItemList();
}
});
etInput.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_ENTER){
addItemList();
}
return false ;
}
});
Pinput.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(keyCode== KeyEvent.KEYCODE_NUM) {
addItemList();
}
return;
}
});
}
protected void addItemList() {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
if (isInputValid(Pinput )) {
itemArrey.add(Pinput.getText().toString());
itemArrey.add(etInput.getText().toString());
Pinput.setText("");
etInput.setText("");
itemAdapter.notifyDataSetChanged();
} if (isInputValid(etInput )) {
itemArrey.add(Pinput.getText().toString());
itemArrey.add(etInput.getText().toString());
Pinput.setText("");
etInput.setText("");
itemAdapter.notifyDataSetChanged();
}
}
protected boolean isInputValid(EditText etInput2 ) {
// TODO Auto-generatd method stub
if (etInput2.getText().toString().trim().length()<1) {
return false;
} else {
return true;
}
}
}
If you want a custom view in your ListView I recommend doing one xml layout by yourself and replace android.R.layout.simple_list_item_1 in your Adapter call with the new created one.
This would be the easiest way but as I think that you might need more freedom to create/modify the content of the row, I strongly suggest to create your own Adapter extending from BaseAdapter. In the getView() method of the adapter you can easily inflate and set up the layout like you want for that row.
Okie... you tag android-listview and list view item. So I think you need list view with image and and Text.
For that you have to use Custom List View.
See this
May be this will help you. and not then pls make your que more clear. :)

Categories

Resources