Hide textview in Listview row based on condition - android

I have a code here that displays data in custom listview from my database
List<Map<String, String>> data1 = new ArrayList<Map<String, String>>();
while (data.moveToNext()) {
Map<String, String> datum = new HashMap<String, String>(5);
datum.put("Customer Name", data.getString(0));
datum.put("Address", data.getString(1));
datum.put("Remarks", data.getString(2));
datum.put("Date", data.getString(3));
datum.put("Code", data.getString(4));
data1.add(datum);
}
adapter = new SimpleAdapter(getActivity(), data1,
R.layout.listview_plan,
new String[]{"Customer Name", "Address", "Remarks", "Date", "Code"},
new int[]{R.id.list_name,
R.id.list_address,
R.id.list_remarks,
R.id.list_date, R.id.list_code});
listView.setAdapter(adapter);
count.setText("" + listView.getAdapter().getCount());
My question is during population I want to add some condition like hiding a textview. How can I do that?
sample
ListView.Populate{
if (data.getString(3)) == null) {
//Hide the label on that row
}
}
My target is to hide a specific textview in listview

Related

Size limit on the size of strings in an ExpandableListView?

I need to display 5 different groups of strings. Some of the items in these strings are one or two sentences long. I was considering using an expandablelistview. The user could click one of the 5 categories and it would open up with all the strings.
Is there a string cut off for strings in an expandablelistview and listview or a way to display more then a sentence of information? I don't want the strings to get cut off. Note, I am not asking about the number of elements in the list.
public class HappyStuff extends ExpandableListActivity {
private static final String NAME = "NAME";
private static final String IS_EVEN = "IS_EVEN";
private ExpandableListAdapter mAdapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.somelayout);
List<Map<String, String>> someData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> someotherData = new ArrayList<List<Map<String, String>>>();
//FROM HERE
for (int i = 0; i < 1; i++) {
Map<String, String> curGroupMap = new HashMap<String, String>();
someData.add(curGroupMap);
curGroupMap.put(NAME, "It's a wonderful life");
curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");
List<Map<String, String>> children3 = new ArrayList<Map<String, String>>();
{
Map<String, String> curChildMap = new HashMap<String, String>();
children3.add(curChildMap);
curChildMap.put(IS_EVEN, "And it's a beautiful day in the neighborhood");
}
someotherdata.add(children3);
}
//TO HERE
//YOU CAN JUST KEEP ON ADDING NEW INSTANCES
supermagnificentAdapter = new SimpleExpandableListAdapter(
this,
someData,
R.layout.somespecialtypeoflayout,
new String[] { NAME, IS_EVEN },
new int[] { R.id.text1, R.id.text2 },
childData,
R.layout.rowsimpleitemlist2,
new String[] { NAME, IS_EVEN },
new int[] { R.id.text1, R.id.text2 }
);
setListAdapter(supermagnificentAdapter);
}
}

I need to retrieve primary, secondary category and source from JSON data and list it in a listView. And on running the app I get an empty listView

if supplier id is !=0 then
if(user.getString("iSupplierID")!="0")
{
String SUPPLIER_NAME=user.getString(TAG_NAME);
String PRIMARY_SERVICE_CATEGORY = user.getString(TAG_PRIMARY);
String SECONDARY_SERVICE_CATEGORY = user.getString(TAG_SECONDARY);
String SOURCE_DIRECTORY_TYPE = user.getString(TAG_SOURCE);
Adding value HashMap key => value
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_NAME, SUPPLIER_NAME);
map.put(TAG_PRIMARY, PRIMARY_SERVICE_CATEGORY);
map.put(TAG_SECONDARY, SECONDARY_SERVICE_CATEGORY);
map.put(TAG_SOURCE, SOURCE_DIRECTORY_TYPE);
supplierlist.add(map);
creating an id for list view
lv=(ListView)findViewById(R.id.listView1);
listview adapter
ListAdapter adapter = new SimpleAdapter(SupplierDetails.this, supplierlist,
R.layout.list_view,
new String[] { TAG_NAME,TAG_PRIMARY,TAG_SECONDARY, TAG_SOURCE }, new int[] {
R.id.primary,R.id.secondary, R.id.source});
lv.setAdapter(adapter);

android: How to remove listview all items with SimpleAdapter

I have a ListView with a SimpleAdapter. The Data for the ListView comes from Sqlite.I want to remove the all the listview items when query result is empty.
How to remove listview all items with SimpleAdapter ?
SimpleAdapter adapter;
ArrayList<HashMap<String, String>> urunsorgu_liste;
Veritabani db = new Veritabani(getActivity().getApplicationContext());//My database class
urunsorgu_liste =db.sorgu(sehirSp, urunSp);
if(urunsorgu_liste.size()==0)// if query result is empty
{
Toast.makeText(getActivity(), "Query is epty", Toast.LENGTH_SHORT).show();
// ??????
}
else{
List<HashMap<String, String>> sorguMaps = new ArrayList<HashMap<String, String>>();
urun_idler = new int[urunsorgu_liste.size()];
for(int i=0;i<urunsorgu_liste.size();i++){
HashMap<String, String> map = new HashMap<String, String>();
String ad=urunsorgu_liste.get(i).get("urun_adi");
String etiket=urunsorgu_liste.get(i).get("urun_etiket");
String fiyat=urunsorgu_liste.get(i).get("urun_fiyat");
String sehir=urunsorgu_liste.get(i).get("urun_sehir");
urun_idler[i] =Integer.parseInt(urunsorgu_liste.get(i).get("id"));
map.put("ADI",ad);
map.put("ETIKETI",etiket);
map.put("FIYATI",fiyat);
map.put("SEHRI", sehir);
sorguMaps.add(map);
adapter = new SimpleAdapter(getActivity(), sorguMaps, R.layout.sorgu_fragment_list_item, from, to);
listV.setAdapter(adapter);
}
Used .clear() method of ArrayList
ArrayList.clear(From Java Doc):
Removes all of the elements from this list. The list will be empty
after this call returns

Set Text of TextView in ListView

In my ListView, I save my data like this:
public void listview_fuellen(){
DBHelper db = new DBHelper(this);
ListView lv = (ListView) findViewById(R.id.lvKinder);
Cursor c = db.select();
int count = c.getCount();
TextView tv = (TextView) findViewById(R.id.secondLine);
List<String> auswahl = new ArrayList<String>();
List<String> auswahl1 = new ArrayList<String>();
int i = 0;
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$1" + c.getCount());
while(c.moveToNext())
{
auswahl.add(c.getString(c.getColumnIndex("name")));
auswahl1.add(" " + i);
System.out.println("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS" + auswahl.get(i).toString());
i++;
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_black_text,R.id.firstLine, auswahl);
//ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this, R.layout.list_black_text,R.id.secondLine, auswahl1);
lv.setAdapter(adapter);
}
Now, I tried the layout for my listview from here:
http://android-developers.blogspot.co.at/2009/02/android-layout-tricks-1.html
Now, how can I set values for the second line in each ListView-Item or the icon?
EDIT:
I tried it like this now, but there are no entries in my listview then.
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();;
int i = 0;
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$1" + c.getCount());
while(c.moveToNext())
{
//map = new HashMap<String, String>();
map.put("name",c.getString(c.getColumnIndex("name")));
map.put("datum", c.getString(c.getColumnIndex("zeit")));
i++;
}
mylist.add(map);
SimpleAdapter mSchedule = new SimpleAdapter(this, mylist, R.layout.list_black_text, new String[] { "datum",
"name" }, new int[] { R.id.firstLine, R.id.secondLine });
lv.setAdapter(mSchedule);
setListAdapter(mSchedule);
What have I done wrong?
for that you can make a custom adapter and then you can set values for the second line in each ListView-Item.
You can check this link
http://devtut.wordpress.com/2011/06/09/custom-arrayadapter-for-a-listview-android/

Android - Launch Intent within ExpandableListView

I'm trying to figure out if it is possible to launch an intent within an ExpandableListView. Basically one of the "Groups" is Phone Number and its child is the number. I want the user to be able to click it and have it automatically call that number. Is this possible? How?
Here is my code to populate the ExpandableListView using a Map called "data".
ExpandableListView myList = (ExpandableListView) findViewById(R.id.myList);
//ExpandableListAdapter adapter = new MyExpandableListAdapter(data);
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
Iterator it = data.entrySet().iterator();
while (it.hasNext())
{
//Get the key name and value for it
Map.Entry pair = (Map.Entry)it.next();
String keyName = (String) pair.getKey();
String value = pair.getValue().toString();
//Add the parents -- aka main categories
Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put("NAME", keyName);
//Add the child data
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put("NAME", value);
childData.add(children);
}
// Set up our adapter
mAdapter = new SimpleExpandableListAdapter(
mContext,
groupData,
R.layout.exp_list_parent,
new String[] { "NAME", "IS_EVEN" },
new int[] { R.id.rowText1, R.id.rowText2 },
childData,
R.layout.exp_list_child,
new String[] { "NAME", "IS_EVEN" },
new int[] { R.id.rowText3, R.id.rowText4}
);
myList.setAdapter(mAdapter);
You can add an OnChildClickListener to your expandable list view. When OnChildClick is called, you have the group and child position, so you should be able to figure out which phone number was clicked.
Then you just need to fire off an intent to make the phone call, i.e.:
Intent intent = new Intent(Intent.CALL_ACTION);
intent.setData(Uri.parse("tel:+436641234567"));
startActivity(intent);

Categories

Resources