problem with settingText for each and individual edittext in listview.Edittext focus missing..Check my image above which is haveing custom keypad and i need to settext when keypad buttons is pressed.Below is my code. i tried but the focus is going for some other edittext.Please help me out.
private LayoutInflater mInflater;
public ArrayList myItems = new ArrayList();
List < HashMap < String, String >> painItems;
public MyAdapet()
{
mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
painItems = new ArrayList < HashMap < String, String >> ();
HashMap < String, String > map = new HashMap < String, String > ();
for(int i=1;i<10;i++)
{
map.put("row_2", "Location Content");
map.put("row_3","Content");
map.put("row_4", "50");
map.put("row_5", "");
painItems.add(map);
}
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return painItems.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_xml, null);
} else {
}
returnText = (EditText) convertView
.findViewById(R.id.returnedit);
returnText.setInputType(InputType.TYPE_NULL);
//Fill EditText with the value you have in <span id="r774jm31_1" class="r774jm31">data source</span>
//we need to update adapter once we finish with editing
returnText.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
listview.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
returnText.requestFocus();
}
});
return convertView;
}
My Listxml:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="250dp" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:descendantFocusability="afterDescendants"
android:focusable="false"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
My custom List:
<?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:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#cfcfcf"
android:gravity="center">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/seq_bg"
android:layout_centerInParent="true"
/>
<TextView
android:id="#+id/sqlno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="left"
android:text="1"
android:textColor="#000000"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Small"
android:textStyle="bold" />
</RelativeLayout>
<TextView
android:id="#+id/lcontent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="Location"
android:textColor="#ffffff"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Small"
android:textStyle="bold" />
<TextView
android:id="#+id/addcontent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="Add Content"
android:textColor="#ffffff"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Small"
android:textStyle="bold" />
<TextView
android:id="#+id/drop"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="50"
android:textColor="#ffffff"
android:gravity="center"
android:textStyle="bold"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Small"
android:layout_weight="1"
/>
<EditText
android:id="#+id/returnedit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="67"
android:textColor="#000000"
android:textStyle="bold"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Small"
android:layout_weight="1"
/>
<Button
android:id="#+id/viewnotesButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="view Notes"
android:textColor="#000000"
android:textStyle="bold"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Small"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
My clicklisteners for custom kepad is like this:
button0.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
returnText.setText(returnText.getText().toString()+"0");
MyAdapet.notifyDataSetChanged();
}
});
button1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
returnText.setText(returnText.getText().toString()+"1");
MyAdapet.notifyDataSetChanged();
}
});
try this code -
returnText.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
listview.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
returnText.requestFocus();
notifyDataSetChanged(); // for update adapter
}
});
Hope this code helps you !!!
if its not working please let me know i will try to help more.
Related
I have three spinners in a fragment. They are populated from JSON received from a remote server.
I can see that all three spinners have items.
The spinners are spinner_categoria, spinner_marca and spinner_modelo.
The issue is that only spinner_marca and spinner_modelo are showing their items when touched on them.
spinner_categoria shows the first item, but when touched on it, nothing happens, and I know it has 3 other items.
This is my code:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.nuevo_disp_1, container, false);
spinner_modelo = (Spinner) v.findViewById(R.id.spinner_modelos);
layout_modelos = (LinearLayout) v.findViewById(R.id.layout_modelos);
//CATEGORIAS
txt_categoria = (TextView) v.findViewById(R.id.txt_categoria);
spinner_categoria = (Spinner) v.findViewById(R.id.spinner_categorias);
layout_categorias = (LinearLayout) v.findViewById(R.id.layout_categorias);
adapterCategoria = new AdapterCategorias(getActivity(), listCategorias);
spinner_categoria.setAdapter(adapterCategoria);
spinner_categoria.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
txt_categoria.setText("Categoría seleccionada : " + listCategorias.get(position).getNombre());
layout_marcas.setVisibility(View.VISIBLE);
callDataMarcas();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
//MARCAS
spinner_marca = (Spinner) v.findViewById(R.id.spinner_marcas);
layout_marcas = (LinearLayout) v.findViewById(R.id.layout_marcas);
txt_marca = (TextView) v.findViewById(R.id.txt_marca);
spinner_marca = (Spinner) v.findViewById(R.id.spinner_marcas);
layout_marcas.setVisibility(View.GONE);
adapterMarca = new AdapterMarcas(getActivity(), listMarcas);
spinner_marca.setAdapter(adapterMarca);
spinner_marca.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
txt_marca.setText("Marca seleccionada : " + listMarcas.get(position).getNombre());
layout_modelos.setVisibility(View.VISIBLE);
callDataModelos();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
//MODELOS
txt_modelo = (TextView) v.findViewById(R.id.txt_modelo);
spinner_modelo = (Spinner) v.findViewById(R.id.spinner_modelos);
adapterModelo = new AdapterModelos(getActivity(), listModelos);
spinner_modelo.setAdapter(adapterModelo);
spinner_modelo.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
txt_modelo.setText("Modelo seleccionado : " + listModelos.get(position).getNombre());
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
callDataCategorias();
return v;
}
What is wrong on it?
EDIT
XML from the fragment:
<?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"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="#+id/marcas"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/layout_categorias"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txtbusqueda"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Elige categoría:"
android:textSize="20dp"
android:textStyle="bold" />
<Spinner
android:id="#+id/spinner_categorias"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/txt_categoria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Categoría seleccionada:"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout_marcas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layout_categorias"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Elige marca:"
android:textSize="20dp"
android:textStyle="bold" />
<Spinner
android:id="#+id/spinner_marcas"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/txt_marca"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Marca seleccionada:"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout_modelos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layout_marcas"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Elige modelo:"
android:textSize="20dp"
android:textStyle="bold" />
<Spinner
android:id="#+id/spinner_modelos"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/txt_modelo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Modelo seleccionado:"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
am doing an android application, in that am loading check boxes in grid view from JSON web services . Up to this it is working perfectly. when i click the check box for the first time it is not triggering the event. but the second time it is working properly. Please help me if anybody knows
My java Code:
#SuppressWarnings("deprecation")
public void showFolderPopUPforEdit() {
int count = 0;
String folderID = null;
String selectedfolderID = null;
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
editpopupView = layoutInflater.inflate(R.layout.edit_folders, null);
editpopupWindow = new PopupWindow(editpopupView,
LayoutParams.MATCH_PARENT, 1060);
editpopupWindow.showAtLocation(editpopupView, Gravity.BOTTOM, 0, 0);
try {
leadna_leadsFolderjsonaray = leadna_leadFoldersjson
.getJSONArray("folderList");
for (int i = 0; i < leadna_leadsFolderjsonaray.length(); i++) {
cb = new CheckBox(this);
cb.setChecked(false);
cb.setFocusable(false);
cb.setFocusableInTouchMode(false);
cb.setBackground(getResources()
.getDrawable(R.drawable.uncheck1));
cb.setButtonDrawable(android.R.color.transparent);
JSONObject c = leadna_leadsFolderjsonaray.getJSONObject(i);
folderID = c.getString("category_id");
for (int j = 0; j < leadna_leadsSelectedFolderjsonaray.length(); j++) {
JSONObject arr2 = leadna_leadsSelectedFolderjsonaray
.getJSONObject(j);
selectedfolderID = arr2.getString("attach_category");
if (folderID.equalsIgnoreCase(selectedfolderID)) {
cb.setChecked(true);
cb.setBackground(getResources().getDrawable(
R.drawable.check_btn));
cb.setFocusable(false);
cb.setFocusableInTouchMode(false);
cb.setButtonDrawable(android.R.color.transparent);
break;
}
}
cb.setText(c.getString("category_name"));
cb.setTextColor(Color.BLACK);
cb.setTextSize((float) 14);
cb.setTag(c.getString("category_id"));
cb.setLayoutParams(new GridView.LayoutParams(346, 90));
cb.setPadding(54, 0, 0, 0);
cb.setOnClickListener(this);
cb.setId(i);
cb.requestFocus();
meditButtons.add(cb);
}
GridView gridView = (GridView) editpopupView
.findViewById(R.id.gridEditView1);
gridView.setAdapter(new CustomAdapter(this, meditButtons));
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Button btnSaveFolders = (Button) editpopupView
.findViewById(R.id.btnAddActivity);
btnSaveFolders.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
Button btnDismiss = (Button) editpopupView.findViewById(R.id.button6);
btnDismiss.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
editpopupWindow.dismiss();
}
});
}
#Override
public void onClick(View v) {
CheckBox selection = (CheckBox)v;
//selection.setCompoundDrawablesWithIntrinsicBounds(R.drawable.clickfolders,0, 0, 0);
selection.requestFocus();
if (selection.isChecked() == true) {
selection.setBackground(getResources().getDrawable(
R.drawable.uncheck1));
//selection.setButtonDrawable(android.R.color.transparent);
} else {
selection.setBackground(getResources().getDrawable(
R.drawable.check_btn));
//selection.setButtonDrawable(android.R.color.transparent);
}
//Toast.makeText(getBaseContext(), selection.getTag()+ " was pressed!", Toast.LENGTH_SHORT).show();
}
My Layout XML :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_black_transparent_90"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="26dp"
android:layout_marginTop="18dp"
android:text="#string/FOLDERS"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView1"
android:layout_marginRight="39dp"
android:visibility="gone" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_red_edit" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/imageView1"
android:text="EDIT"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/darker_gray"
android:textSize="16dp" />
</RelativeLayout>
<GridView
android:id="#+id/gridEditView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/ddd"
android:layout_below="#+id/textView1"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="#android:color/transparent"
android:horizontalSpacing="1dp"
android:numColumns="2"
android:verticalSpacing="1dp" >
</GridView>
<RelativeLayout
android:id="#+id/ddd"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<Button
android:id="#+id/button6"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:background="#drawable/ic_red_cancel_47"
android:gravity="center"
android:visibility="visible" />
<Button
android:id="#+id/btnAddActivity"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:background="#drawable/ic_red_ok_47" />
</RelativeLayout>
</RelativeLayout>
Try to use
checkbox.setOnCheckedChangeListener( new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Check box "+arg0.getText().toString()+" is "+String.valueOf(arg1) , Toast.LENGTH_LONG).show();
}
} );
Instead of clickListener..
I have a list activity with string array, And when I click the list item (convertview) I want to edit my string.
Once I edit one string then I pressed Guncelle Button I see new text , everythink is oke.
But when I refresh the list I dont see new text. It doesnt change.
I use notifyDataSetChanged but I think its not working. How can I solve this problem.
public class huawei_list extends ListActivity {
private static int selected_item = -1;
private String[] phones = { "(0554) 741 xx xx", "(0554) 582 xx xx",
"(0543) 613 xx xx", "(0543) 613 xx xx", "(0507) 183 xx xx",
"(0216) 444 xx xx" };
private String[] birimler = { "HUAWEI NOBET", "NAZMİ İŞLER", "DENİZ NAMAL",
"OKTAY TATAR", "ALP SİVRİ", "HUAWEI ACİL DESTEK" };
private telefonlarAdapter mAdapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// birimler = getResources().getStringArray(R.array.birimler_huawei);
mAdapter = new telefonlarAdapter();
setListAdapter(mAdapter);
}
private static class AccessoriesViewHolder {
public ListView list;
public ImageView list_image;
public TextView textview_list;
public TextView textview_list2;
}
private class telefonlarAdapter extends BaseAdapter {
#Override
public int getCount() {
// TODO Auto-generated method stub
return birimler.length;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return birimler[position];
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(final int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
AccessoriesViewHolder holder = null;
if (convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.single_row,
parent, false);
holder = new AccessoriesViewHolder();
holder.list_image = (ImageView) convertView.findViewById(R.id.list_image);
holder.textview_list = (TextView) convertView.findViewById(R.id.textview_list);
holder.textview_list2 = (TextView) convertView.findViewById(R.id.textview_list2);
holder.list = (ListView) convertView.findViewById(R.layout.single_row);
convertView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Toast.makeText(getApplicationContext(),
// "Bu Tıkladığınız "+position+". satırdır" ,
// 1000).show();
selected_item = position;
final Dialog dialog_guncelle = new Dialog(
huawei_list.this);
dialog_guncelle.setContentView(R.layout.dialog);
dialog_guncelle.setCancelable(true);
dialog_guncelle.setTitle(birimler[selected_item]);
dialog_guncelle.show();
ImageView dialogresim = (ImageView) dialog_guncelle.findViewById(R.id.imageView1);
TextView guncelleText = (TextView) dialog_guncelle.findViewById(R.id.guncelle_text);
final EditText editIsim = (EditText) dialog_guncelle.findViewById(R.id.editText_isim);
final EditText editTelefone = (EditText) dialog_guncelle.findViewById(R.id.editText_telefone);
Button guncelle = (Button) dialog_guncelle.findViewById(R.id.guncelle);
Button iptalButon = (Button) dialog_guncelle.findViewById(R.id.iptal);
guncelleText.setText(birimler[selected_item]);
editIsim.setText(birimler[selected_item]);
editTelefone.setText(phones[selected_item]);
iptalButon.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog_guncelle.cancel();
}
});
guncelle.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
birimler[selected_item] = editIsim.getText().toString();
phones[selected_item] = editTelefone.getText().toString();
notifyDataSetChanged();
dialog_guncelle.dismiss();
}
});
}
});
((Button) convertView.findViewById(R.id.call_button))
.setOnClickListener(call_buttonClisckListener);
convertView.setTag(holder);
} else {
holder = (AccessoriesViewHolder) convertView.getTag();
}
String s = phones[position];
holder.textview_list.setText(phones[position]);
holder.textview_list2.setText(birimler[position]);
if (s.contains("(0216)")) {
holder.list_image.setImageResource(R.drawable.masaustuphone);
} else {
holder.list_image.setImageResource(R.drawable.gsm);
}
return convertView;
}
}
private OnClickListener call_buttonClisckListener = new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Cyril: Not implemented yet!
final int position = getListView().getPositionForView(v);
if (position != ListView.INVALID_POSITION) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + phones[position]));
startActivity(intent);
// Toast.makeText(getApplicationContext(),
// ""+getResources().getStringArray(R.array.huawei_rsmc)[position],
// Toast.LENGTH_SHORT).show();
}
}
};
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
if (item.getItemId() == R.id.aboutmenu)
;
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.popup);
dialog.setTitle("İLETİŞİM");
dialog.setCancelable(true);
dialog.show();
TextView hakkindamail = (TextView) dialog
.findViewById(R.id.hakkindamail);
TextView hakkindamobile = (TextView) dialog
.findViewById(R.id.hakkindamobile);
hakkindamobile.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:0507771xxxx"));
startActivity(intent);
}
});
hakkindamail.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
String[] TO = { "mustafa.kayahan#xxxxx.com" };
Intent intentmail = new Intent(Intent.ACTION_SEND);
intentmail.setData(Uri.parse("mailto:"));
intentmail.putExtra(Intent.EXTRA_EMAIL, TO);
intentmail.putExtra(intentmail.EXTRA_SUBJECT,
"SMC REHBER HAKKINDA");
intentmail.setType("text/plain");
try {
startActivity(Intent.createChooser(intentmail,
"Send mail..."));
finish();
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(huawei_list.this,
"There is no email client installed.",
Toast.LENGTH_SHORT).show();
}
}
});
return super.onOptionsItemSelected(item);
}
}
This is my custom layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="#+id/list_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
<Button
android:id="#+id/call_button"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignBottom="#+id/list_image"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/selector"
android:focusable="false"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="0"
android:text="Ara"
android:textColor="#ffffff"
android:textSize="30sp" />
<TextView
android:id="#+id/textview_list2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/list_image"
android:text=""
android:textStyle="bold"
android:textColor="#color/birimler"/>
<TextView
android:id="#+id/textview_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/list_image"
android:layout_alignLeft="#+id/textview_list2"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textview_list3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textview_list2"
android:layout_below="#+id/textview_list2"
android:text=""
android:textSize="8sp"/>
</RelativeLayout>
Dialog Layout
<?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:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/userinfoicon" />
<TextView
android:id="#+id/guncelle_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:text="Large Text"
android:textSize="25dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="56dp"
android:layout_height="wrap_content"
android:text="İsim"
android:textSize="20sp" />
<EditText
android:id="#+id/editText_isim"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView4"
android:layout_width="56dp"
android:layout_height="wrap_content"
android:text="Tel"
android:textAlignment="center"
android:textSize="20sp" />
<EditText
android:id="#+id/editText_telefone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.86"
android:inputType="textNoSuggestions" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/guncelle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:background="#drawable/selector"
android:text="Güncelle"
android:textColor="#FFFF" />
<Button
android:id="#+id/iptal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:background="#drawable/selector"
android:text="İptal"
android:textColor="#FFFF" />
</LinearLayout>
</LinearLayout>
just Recall your adapter and Bind Data further after adding new data to StringArray.
Replace
notifyDataSetChanged();
with
mAdapter = new telefonlarAdapter();
setListAdapter(mAdapter);
and if setListAdapter(mAdapter); method not working in your Adapter class just set id of listview and get id using viewbyid then set adapter to it.
Thats it...
I want to create a custom list view in app...
but I don't understand why my code have problem to run it
when I run my app ...Shows Message as "app is stopped" ..
I'm confused..
Help me to solve this
thank you
java code:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView list=(ListView) findViewById(R.id.listView1);
Myadapter adapter=new Myadapter(getApplicationContext());
list.setAdapter(adapter);
}
public class Myadapter extends BaseAdapter
{
LayoutInflater myInflater;
public Myadapter(Context context) {
myInflater=LayoutInflater.from(context);
// TODO Auto-generated constructor stub
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return (4);
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder Holder;
if(convertView==null)
{
Holder=new ViewHolder();
convertView=myInflater.inflate(R.layout.item_layout, null);
Holder.star=(ImageButton) convertView.findViewById(R.id.imageButton_star);
Holder.vorod=(Button) convertView.findViewById(R.id.button_voro);
Holder.url=(TextView) convertView.findViewById(R.id.text_addres);
Holder.vorod=(Button)convertView.findViewById(R.id.imageButton_star);
Holder.rank=(ImageButton) convertView.findViewById(R.id.imageButton_rank);
Holder.speed=(ImageButton) convertView.findViewById(R.id.imageView_speed);
Holder.delete=(ImageButton) convertView.findViewById(R.id.imageButton_delete);
convertView.setTag(Holder);
}
else
Holder=(ViewHolder) convertView.getTag();
// TODO Auto-generated method stub
return convertView;
}
}
public class ViewHolder
{
ImageButton star;
Button vorod;
TextView url;
ImageButton rank;
ImageButton speed;
ImageButton detail;
ImageButton delete;
}
}
Xml code:(Item list view)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="30dp"
android:background="#drawable/image001"
android:orientation="vertical" >
<ImageButton
android:id="#+id/imageButton_star"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:background="#drawable/round"
android:src="#drawable/star1"
/>
<Button
android:id="#+id/button_voro"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/text_addres"
android:background="#drawable/corner_round"
android:text="button" />
<TextView
android:id="#+id/text_addres"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="9dp"
android:layout_margin="30dp"
android:layout_centerInParent="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="30dp"
android:background="#drawable/olgo"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/imageView_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round"
android:layout_margin="5dp"
android:layout_weight="1"
android:src="#drawable/speed" />
<ImageButton
android:id="#+id/imageButton_dataile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round"
android:layout_margin="5dp"
android:layout_weight="1"
android:src="#drawable/dataile" />
<ImageButton
android:id="#+id/imageButton_rank"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round"
android:layout_margin="5dp"
android:layout_weight="1"
android:src="#drawable/ranke" />
<ImageButton
android:id="#+id/imageButton_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round"
android:layout_margin="5dp"
android:layout_weight="1"
android:src="#drawable/delete" />
</LinearLayout>
and main Xml: There is a listView
you have this in code:
Holder.star=(ImageButton) convertView.findViewById(R.id.imageButton_star);
but you have not a Button with id imageButton_star in your xml file.
You are inilizating Holder.vorod twice
Remove
Holder.vorod=(Button)convertView.findViewById(R.id.imageButton_star);
I'm trying to implement a custom ExpandableListView inside a SherlockFragment. I followed this sample to extend BaseExpandableListAdapter and create my custom adapter.
Here is my problem, when my expandable list is displayed on the screen I can see all the group item, but when I click on one of them, the child item which are supposed to be displayed below it don't show up.
I tried to debug it, the onGroupExpandListener I put in the adapter is never called, and actually I put breakpoints in the different methods of my adapter, there are not called ever when I click on one of the group item.
I tried to modify my xml files which define the group item and the child item, to make them clickable or focus-able, nothing changed. I also tried to remove the editText, Button, and CheckBox I put in there, thinking it was may be creating a conflict ...
I thought the problem was may be due to some incompatibility issues using ExpandableListView with SherlockFragment, but according to the developer's forum its not.
So I really don't know where to look now, it's may be simply a rookie mistake I did in my adapter...
Any help would be great,
Thanks in advance!
here is my code:
public class BuildingExpandalbeListAdapter extends BaseExpandableListAdapter {
private Context mContext;
private ExpandableListView mExpandableListView;
private SideEntity[] mSidesCollection;
private int[] groupStatus;
public BuildingExpandalbeListAdapter(Context pContext,
ExpandableListView pExpandableListView,
SideEntity[] pSidesCollection) {
mContext = pContext;
mSidesCollection = pSidesCollection;
mExpandableListView = pExpandableListView;
groupStatus = new int[mSidesCollection.length];
mExpandableListView.setClickable(true);
setListEvent();
}
private void setListEvent() {
mExpandableListView
.setOnGroupExpandListener(new OnGroupExpandListener() {
#Override
public void onGroupExpand(int arg0) {
// TODO Auto-generated method stub
groupStatus[arg0] = 1;
}
});
mExpandableListView
.setOnGroupCollapseListener(new OnGroupCollapseListener() {
#Override
public void onGroupCollapse(int arg0) {
// TODO Auto-generated method stub
groupStatus[arg0] = 0;
}
});
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return mSidesCollection[groupPosition].getSegmentEntity(childPosition)
.getName();
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return mSidesCollection[groupPosition].getSegmentEntity(childPosition)
.getId();
}
#Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ChildHolder childHolder;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(
R.layout.building_list_item, null);
childHolder = new ChildHolder();
childHolder.editText1 = (EditText) convertView
.findViewById(R.id.editText1);
childHolder.checkBox1 = (CheckBox) convertView
.findViewById(R.id.checkBox1);
convertView.setTag(childHolder);
} else {
childHolder = (ChildHolder) convertView.getTag();
}
childHolder.editText1.setText(mSidesCollection[groupPosition]
.getSegmentEntity(childPosition).getName());
childHolder.checkBox1.setChecked(mSidesCollection[groupPosition]
.getSegmentEntity(childPosition).hasDoor());
return convertView;
}
#Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return mSidesCollection[groupPosition].getSegmentsCollection().size();
}
#Override
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return mSidesCollection[groupPosition];
}
#Override
public int getGroupCount() {
// TODO Auto-generated method stub
return mSidesCollection.length;
}
#Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
GroupHolder groupHolder;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(
R.layout.building_list_group, null);
groupHolder = new GroupHolder();
groupHolder.editText1 = (EditText) convertView
.findViewById(R.id.editText1);
groupHolder.editText2 = (EditText) convertView
.findViewById(R.id.editText2);
convertView.setTag(groupHolder);
} else {
groupHolder = (GroupHolder) convertView.getTag();
}
groupHolder.editText1
.setText(mSidesCollection[groupPosition].getName());
groupHolder.editText2.setText(Integer
.toString(mSidesCollection[groupPosition]
.getSegmentsCollection().size()));
return convertView;
}
class GroupHolder {
EditText editText1;
EditText editText2;
}
class ChildHolder {
EditText editText1;
CheckBox checkBox1;
}
#Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
}
Here is my SherlockFragment using this adapter :
public class BuildingFragment extends SherlockFragment {
private ViewGroup myViewGroup;
private View v;
private SideEntity[] mSideCollection;
private BuildingsDbAdapter buildingDataBase;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null) {
return null;
}
myViewGroup = container;
myViewGroup.removeAllViews();
v = inflater.inflate(R.layout.building_data_layout, container, false);
buildingDataBase = new BuildingsDbAdapter(getSherlockActivity());
return v;
}
#Override
public void onResume() {
super.onResume();
buildingDataBase.open();
mSideCollection = BuildingsDbAdapter
.fetchSideMatchingBuildingId(CustomTabFragmentActivity.mBuildingId);
for (int i = 0; i < mSideCollection.length; i++) {
BuildingsDbAdapter.fetchSegmentMatchingSideId(
mSideCollection[i].getId(), mSideCollection[i]);
}
ExpandableListView mExpandableListView = (ExpandableListView) v
.findViewById(R.id.expandableListView1);
BuildingExpandalbeListAdapter mAdapter = new BuildingExpandalbeListAdapter(
v.getContext().getApplicationContext(), mExpandableListView,
mSideCollection);
mExpandableListView.setAdapter(mAdapter);
buildingDataBase.close();
}
}
and here is my xml files :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="10dip"
android:layout_weight="3"
android:singleLine="true"
android:text="Building name: "
android:textColor="#android:color/black"
android:textSize="13dip" />
<TextView
android:id="#+id/textView2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="10dip"
android:layout_weight="4"
android:singleLine="true"
android:text="Columbia Tower"
android:textColor="#android:color/black"
android:textSize="15dip"
android:textStyle="italic" />
<!-- <Button
android:id="#+id/button1"
android:layout_width="0dip"
android:layout_height="30dp"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="10dip"
android:layout_weight="1"
android:background="#color/honeycombish_blue"
android:drawableTop="#drawable/edit_query"
android:gravity="center_vertical|center_horizontal" /> -->
</LinearLayout>
<ExpandableListView
android:id="#+id/expandableListView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:divider="#android:color/black"
android:clipChildren="false"
android:focusable="true" >
</ExpandableListView>
</LinearLayout>
the group_item :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/RelativeLayout"
android:layout_marginTop="6dip"
android:layout_toLeftOf="#+id/button1"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="5dip"
android:layout_weight="2"
android:singleLine="true"
android:text="Side: "
android:textColor="#android:color/black"
android:textSize="13dip" />
<EditText
android:id="#+id/editText1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="5dip"
android:layout_weight="2"
android:singleLine="true"
android:textColor="#android:color/black"
android:textSize="15dip"
android:textStyle="italic" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="5dip"
android:layout_weight="5"
android:singleLine="true"
android:text="Number of Segment:"
android:textColor="#android:color/black"
android:textSize="13dip" />
<EditText
android:id="#+id/editText2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="5dip"
android:layout_weight="2"
android:ems="10"
android:inputType="number"
android:text="0"
android:textSize="13dip" />
</LinearLayout>
<Button
android:id="#+id/button1"
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_alignBottom="#+id/linearLayout1"
android:layout_alignParentRight="true"
android:layout_marginLeft="2dip"
android:background="#android:color/transparent"
android:drawableBottom="#drawable/ic_edit_shape"
android:gravity="bottom|center_horizontal" />
</RelativeLayout>
the list_item :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_alignBottom="#+id/linearLayout1"
android:layout_alignParentLeft="true"
android:layout_marginLeft="2dip"
android:background="#android:color/transparent"
android:drawableBottom="#drawable/ic_edit_shape"
android:gravity="bottom|center_horizontal" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/RelativeLayout"
android:layout_marginTop="6dip"
android:layout_toRightOf="#+id/button1"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="5dip"
android:layout_weight="2"
android:singleLine="true"
android:text="Name: "
android:textColor="#android:color/black"
android:textSize="13dip" />
<EditText
android:id="#+id/editText1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="5dip"
android:layout_weight="2"
android:singleLine="true"
android:text="Shop1"
android:textColor="#android:color/black"
android:textSize="15dip"
android:textStyle="italic" />
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="0dip"
android:layout_height="30dip"
android:layout_weight="1"
android:hint="Door" />
</LinearLayout>
</RelativeLayout>
Ok I find my mistake, the problem was in fact coming from both EditText and the Button I have been using in my group items. When I set this widgets to non clickable and non focusable the click on my group items perform normally.
I should have detected this conflict sooner, I tried before to remove both my Button and my EditText, but i forgot that at some point I had try to add android:clickable="true" to my RelativeLayout (thinking it would allowed the click on my group items) but instead it has also created a conflict :/
Anyway, if someone has a similar problem, keep in mind to check if any of your view inside your group item is clickabble or focusable and set them to android:clickable="false" android:focusable="false"