TextView update not happening when selected item from ListView - android

Hi I have Listview in that when I select an item I display another page where I am setting the text views with appropriate informations but when i select an item and go back and select another item the textviews are not getting updated ?BTW there are 10 text views can somebody provide me the solution for this? Thanks.
super.onCreate(savedInstanceState);
setContentView(R.layout.lastl);
Intent i = getIntent();
ACK = i.getStringExtra("ack-no");
NAME = i.getExtras().getString("appl name");
TRADE = i.getExtras().getString("trade");
PIN = i.getExtras().getString("pin");
MOBILE = i.getExtras().getString("mobile");
EMAIL = i.getExtras().getString("email");
LVO1 = i.getExtras().getString("LVO1");
LVO2 = i.getExtras().getString("LVO2");
tv1 = (TextView) findViewById(R.id.set_ack);
tv1.setText(ACK);
tv2 = (TextView) findViewById(R.id.set_apl);
tv2.setText(NAME);
tv3 = (TextView) findViewById(R.id.set_trd);
tv3.setText(TRADE);
tv4 = (TextView) findViewById(R.id.set_dr);
tv4.setText(ArrayAdapter.ar.get(0));
tv5 = (TextView) findViewById(R.id.set_flr);
tv5.setText(ArrayAdapter.ar.get(1));
tv6 = (TextView) findViewById(R.id.set_bdg);
tv6.setText(ArrayAdapter.ar.get(2));
tv7 = (TextView) findViewById(R.id.set_str);
tv7.setText(ArrayAdapter.ar.get(3));
tv8 = (TextView) findViewById(R.id.set_area);
tv8.setText(ArrayAdapter.ar.get(4));
tv9 = (TextView) findViewById(R.id.set_dis);
//tv9.setText(ArrayAdapter.ar.get(5));
tv10 = (TextView) findViewById(R.id.set_pin);
tv10.setText(PIN);
tv11 = (TextView) findViewById(R.id.set_mb);
tv11.setText(MOBILE);
tv12 = (TextView) findViewById(R.id.set_email);
tv12.setText(EMAIL);
tv13 = (TextView) findViewById(R.id.set_pn);
tv14 = (TextView) findViewById(R.id.set_bdgg);
tv15 = (TextView) findViewById(R.id.set_dt);
tv16 = (TextView) findViewById(R.id.set_lvo);
tv16.setText(LVO1);
String lvo2 = LVO2.substring(0, LVO2.length() - 1);
Log.d("sssssss", lvo2);
tv17 = (TextView) findViewById(R.id.set_lvo2);
tv17.setText(lvo2);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(this);
b2 = (Button) findViewById(R.id.button2);
b2.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
break;
case R.id.button2:
break;
}
}
this is my listView code
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listmain);
pv = getIntent().getStringArrayListExtra("Array_list");
System.out.println("ARRAYLIST---->" + pv);
final ListView list = (ListView) findViewById(R.id.listView1);
mylistData = new ArrayList<HashMap<String, String>>();
String[] columnTags = new String[]{"col1", "col2", "col3", "col4", "col5", "col6", "col7", "col8"};
int[] columnIds = new int[]{R.id.col1, R.id.col2, R.id.col3, R.id.col4, R.id.col5, R.id.col6, R.id.col7, R.id.col8};
int k = 0;
for (int i = 0; i <= 9; i++) {
HashMap<String, String> map = new HashMap<String, String>();
//initialize row data
for (int j = 0; j <= 7/*pv.size()-1*/; j++) {
map.put(columnTags[j], pv.get(k));
put(columnTags[j], "row" + i + "col" + j);
k++;
}
mylistData.add(map);
}
SimpleAdapter arrayAdapter = new SimpleAdapter(this, mylistData, R.layout.rowmain, columnTags, columnIds);
list.setAdapter(arrayAdapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parnet, android.view.View view, int position, long id) {
new LongOperation().execute();
String text = list.getItemAtPosition(position).toString();
String g = text.replace("{col5=", "");
String g1 = g.replace(" col4=", "");
String g2 = g1.replace(" col7=", "");
String g3 = g2.replace(" col6=", "");
String g4 = g3.replace(" col1=", "");
String g5 = g4.replace(" col3=", "");
String g6 = g5.replace(" col2=", "");
String g7 = g6.replace(" col8=", "");
String val[] = g7.split(",");
for (int m = 0; m < val.length; m++) {
Log.d("VALUE", val[m]);
ar1.add(val[m]);
}
System.out.println(ar1);
Log.d("VALUES-------->", text);
mob = ar1.get(0);
Log.d("VALUE1", mob);
pin = ar1.get(1);
Log.d("VALUE2", pin);
lvo = ar1.get(2);
Log.d("VALUE3", lvo);
email = ar1.get(3);
Log.d("VALUE4", email);
ack = ar1.get(4);
Log.d("VALUE5", ack);
trade = ar1.get(5);
Log.d("VALUE6", trade);
name = ar1.get(6);
Log.d("VALUE7", name);
lvo2 = ar1.get(7);
Log.d("VALUE8", lvo2);
}
});
}

From your code: ar1.add(val[m]);
I guess that ar1 is a List<String> variable of your listview activity?
If that's true, maybe add a call to clear() may work:
ar1.clear();
for(int m =0 ; m< val.length ; m++)
{
Log.d("VALUE",val[m]);
ar1.add(val[m]);
}

Related

how to add fast data in view inflate with layout

its is working fine but its taking too much time for arraylist size 7000 . is there any other way to display this report in fast way.to display 1000 row its taking 3 minutes which very huge time .can we use another way to make this report instead of uving view inflate with layout which will work fast.Thank in advance
spinner=(Spinner)findViewById(R.id.searchableSpinnerLedgerReport);
spinner.setAdapter(new ArrayAdapter<>(LedgerReportActivity.this,R.layout.support_simple_spinner_dropdown_item,numberlist));
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(position==-1){
Toast.makeText(getApplicationContext(), "plz select number", Toast.LENGTH_SHORT).show();
}
else {
String snumber= parent.getItemAtPosition(position).toString();
ArrayList<HashMap<String, String>> myList=ledgerReportDataCon.getSelectedReport(snumber); //size of comming data is 7000
Log.d("size of report list", String.valueOf(myList.size()));
// Log.d("name",snumber);
if(Float.parseFloat (myList.get(0).get(ConstLedgerReport.key_cLOSING))>0)
{
tclosingblnc.setText(myList.get(0).get(ConstLedgerReport.key_cLOSING));
}
else {
tclosingblnc2.setText(myList.get(0).get(ConstLedgerReport.key_cLOSING));
}
if(Float.parseFloat(myList.get(0).get(ConstLedgerReport.key_oPENING))>0)
{
topeningblnc.setText(myList.get(0).get(ConstLedgerReport.key_oPENING));
}
else {
topeningblnc2.setText(myList.get(0).get(ConstLedgerReport.key_oPENING));
}
for(int i=0;i<myList.size();i++) {
String ledgertype=myList.get(i).get(ConstLedgerReport.key_lEDGERTYPE);
String narration=myList.get(i).get(ConstLedgerReport.key_nARRATION);
final View partyView = getLayoutInflater().inflate(R.layout.ledger_report_item, null, false);
LinearLayout headerLayout=(LinearLayout) partyView.findViewById(R.id.headder);
TextView particular = (TextView) partyView.findViewById(R.id.particular);
TextView vchType = (TextView) partyView.findViewById(R.id.vchType);
TextView debit = (TextView) partyView.findViewById(R.id.debit);
TextView credit = (TextView) partyView.findViewById(R.id.credit);
TextView date = (TextView) partyView.findViewById(R.id.date);
TextView vchno = (TextView) partyView.findViewById(R.id.vchno);
particular.setText( myList.get(i).get(ConstLedgerReport.key_pARTICULARS));
vchType.setText( myList.get(i).get(ConstLedgerReport.key_vCHTYPE));
date.setText( myList.get(i).get(ConstLedgerReport.key_vCHDATE));
vchno.setText( myList.get(i).get(ConstLedgerReport.key_vCHNUM));
if (ledgertype.equalsIgnoreCase("Dr"))
{
debit.setText( myList.get(i).get(ConstLedgerReport.key_lEDGERAMT));
totaldebit=totaldebit+Float.parseFloat( myList.get(i).get(ConstLedgerReport.key_lEDGERAMT));
}
else if (ledgertype.equalsIgnoreCase("Cr"))
{
credit.setText( myList.get(i).get(ConstLedgerReport.key_lEDGERAMT));
totalcredit=totalcredit+Float.parseFloat( myList.get(i).get(ConstLedgerReport.key_lEDGERAMT));
}
listViewLayout.addView(partyView);
String[] itemArr=narration.split("~");
// Log.d("first array is ....: ", Arrays.toString(itemArr));
headerLayout.setVisibility(View.INVISIBLE);
if(!narration.equalsIgnoreCase("Array")) {
for (int j = 0; j < itemArr.length; j++) {
headerLayout.setVisibility(View.VISIBLE);
final View itemListView = getLayoutInflater().inflate(R.layout.ledger_report_itemlist, null, false);
TextView iname = (TextView) itemListView.findViewById(R.id.iname);
TextView iqty = (TextView) itemListView.findViewById(R.id.iqty);
TextView iunit = (TextView) itemListView.findViewById(R.id.iunit);
TextView irate = (TextView) itemListView.findViewById(R.id.irate);
TextView itotal = (TextView) itemListView.findViewById(R.id.itotal);
String temp1 = itemArr[j].replace("]][[", ",");
String temp2 = temp1.replace("[[", "");
String temp3 = temp2.replace("]]", "");
String[] itemArrList = temp3.split(",");
// Log.d("second array is ....: ", Arrays.toString(itemArrList));
iname.setText(itemArrList[0]);
iqty.setText(itemArrList[4]);
iunit.setText(itemArrList[1]);
irate.setText(itemArrList[5]);
itotal.setText(itemArrList[7]);
listViewLayout.addView(itemListView);
// Log.d("created view msz", String.valueOf(j));
}
}
}
tdebit.setText(String.valueOf(totaldebit));
tcredit.setText(String.valueOf(totalcredit));
}
}
enter image description here

How to get edittext position in Listview

I am working on ListView having EditText inside.I have used four EditText in each item of ListView.I am facing problem with getting the position of EditText in the ListView. Below is my code. I am able to fetch the position of TextView,but while fetching the position of EditText I am facing problem.
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
myproductpercarton = (TextView) view.findViewById(R.id.txtorderamount);
final String ssss =(String) ((TextView) view.findViewById(R.id.txtorderamount)).getText();
mytotalprice = (TextView) view.findViewById(R.id.txtprice);
mm = (CheckBox) view.findViewById(R.id.mycheck);
mm.setFocusableInTouchMode(true);
mm.setFocusable(true);
mm2 = (CheckBox) view.findViewById(R.id.mynewcheck);
mm2.setFocusableInTouchMode(true);
mm2.setFocusable(true);
myorderprice = (EditText) view.findViewById(R.id.txtorderby);
myorderprice.setFocusableInTouchMode(true);
myorderprice.setFocusable(true);
mycartonno = (EditText) view.findViewById(R.id.txtordercarton);
mycartonno.setFocusableInTouchMode(true);
mycartonno.setFocusable(true);
myproductno = (EditText) view.findViewById(R.id.txtproduct);
myproductno.setFocusableInTouchMode(true);
myproductno.setFocusable(true);
myproductno.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String myprodpercart;
map = (HashMap<String, String>) getListView().getItemAtPosition(position);
HashMap<String, String> map2 = (HashMap<String, String>) getListView().getItemAtPosition(position);
HashMap<String, String> map3 = (HashMap<String, String>) getListView().getItemAtPosition(position);
double orderId4;
double mycarton2;
double mynewcart;
double myprodno2;
double mycartquantity;
double mytotal;
String mynoocarton;
double mynoocarton44;
int myprodno3;
String temp=mycartonno.getText().toString();
String contents = mycartonno.getText().toString();
orderId4 = new Double(map.get(TAG_PRODUCTPERCARTON));
Log.d("MyOrderId :: ", String.valueOf(orderId4));
mycartonprice2 = map.get(TAG_PRODUCTPERCARTON2);
Log.d("MyCartonPrice :: ", String.valueOf(mycartonprice2));
mynoocarton = mycartonno.getText().toString();
mynoocarton44 = new Double(mycartonno.getText().toString());
mycarton2 = new Double(mynoocarton);
mynewcart = new Double(mycartonprice2);
myprodno2 = new Double(orderId4 * mycarton2);
myprodno3 = new Integer((int) myprodno2);
mycartquantity = new Double(mycartonno.getText().toString());
Log.d("MyCartonNo :: ", mycartonno.getText().toString());
Log.d("MyCartonNo2 :: ",contents);
mytotal = new Double(mycartquantity * mynewcart);
String mynoocarton3 = String.valueOf(mynoocarton44);
String total = String.valueOf(mytotal);
String mm = String.valueOf(myprodno3);
mycartonno.setText(mynoocarton3);
myproductno.setText(mm);
mytotalprice.setText(total);
Toast.makeText(getActivity(), ssss + " " + mynewcart + "----" + mm + " " + total,
Toast.LENGTH_SHORT).show();
}
});
mydiscount = (EditText) view.findViewById(R.id.txtdiscount);
mydiscount.setFocusableInTouchMode(true);
mydiscount.setFocusable(true);
}
});
I solved this issue by myself and now its working fine. I just have taken another textview and two new edittext inside setOnClickListener. I just added below code inside setOnClickListener.
TextView mynewtotal = (TextView) view.findViewById(R.id.txtprice);
EditText mycartonprod = (EditText) view.findViewById(R.id.txtordercarton);
mycartonprod.setFocusableInTouchMode(true);
mycartonprod.setFocusable(true);
EditText myprod = (EditText) view.findViewById(R.id.txtproduct);
myprod.setFocusableInTouchMode(true);
myprod.setFocusable(true);

Images inside a customadapter not updating like strings are to fill a listview

I'll try my best explaining whats happening, so my code has a forloop which fills a listview, this listview is showing all the correct data from a json file, excpet for the images, the images are always from the last position in the listview and then copied to the one above, for example here
This is one single activity which i just and to snippet to make it fit. I'm guessing its something to do with the strings which i create to make the images, they are somehow being used twice, and then used again to fill the listview, even though all of the other strings are being reset and filled when its gets the new information from the JSON. Heres my code if anyone would could tell me why this is only happening to the images and not the strings which create the names of items
String ChampionName;
String item2;
String item3;
String item4;
private String ItemName;
private String ItemName2;
private String ItemName3;
private String ItemName4;
private String ItemName5;
private String ItemName6;
private String ItemNameHW;
private String ItemName2HW;
private String ItemName3HW;
private String ItemName4HW;
private String ItemName5HW;
private String ItemName6HW;
private ListView Champ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// http://api.champion.gg/champion/Ekko/
new JSONTask().execute("http://api.champion.gg/champion/aatrox/");
Champ = (ListView) findViewById(R.id.listView);
}
public class JSONTask extends AsyncTask<String, String, List<Layoutmodel>> {
#Override
protected List<Layoutmodel> doInBackground(String... params) {
HttpURLConnection connection = null;
BufferedReader reader = null;
try {
URL url = new URL(params[0]);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuilder buffer = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
String finalJson = buffer.toString();
JSONArray jsonarray = new JSONArray(finalJson);
List<Layoutmodel> LayoutModelList = new ArrayList<>();
//Number changes to what ever role you want it to be
//JSONObject finalObject = jsonarray.getJSONObject(jsonarray.length()-1);
for (int k = 0; k < jsonarray.length(); k++) {
JSONObject finalObject = jsonarray.getJSONObject(k);
Layoutmodel layoutmodel = new Layoutmodel();
layoutmodel.setChampionName2(finalObject.getString("key"));
layoutmodel.setRole(finalObject.getString("role"));
ChampionName = finalObject.getString("key");
String role = finalObject.getString("role");
String overallPosition = finalObject.getString("overallPosition");
JSONObject ItemArray4 = new JSONObject(overallPosition);
String champpos = ItemArray4.getString("position");
String items = finalObject.getString("items");
JSONObject ItemArray = new JSONObject(items);
item2 = ItemArray.getString("mostGames");
item3 = ItemArray.getString("highestWinPercent");
JSONObject ItemArray2 = new JSONObject(item2);
JSONObject ItemArray3 = new JSONObject(item3);
item3 = ItemArray2.getString("items");
item4 = ItemArray3.getString("items");
JSONArray jsonarray2 = new JSONArray(item3);
JSONArray jsonarray3 = new JSONArray(item4);
JSONObject finalObject2 = jsonarray2.getJSONObject(jsonarray2.length() - 6);
ItemName = finalObject2.getString("name");
JSONObject finalObject3 = jsonarray2.getJSONObject(jsonarray2.length() - 5);
ItemName2 = finalObject3.getString("name");
JSONObject finalObject4 = jsonarray2.getJSONObject(jsonarray2.length() - 4);
ItemName3 = finalObject4.getString("name");
JSONObject finalObject5 = jsonarray2.getJSONObject(jsonarray2.length() - 3);
ItemName4 = finalObject5.getString("name");
JSONObject finalObject6 = jsonarray2.getJSONObject(jsonarray2.length() - 2);
ItemName5 = finalObject6.getString("name");
JSONObject finalObject7 = jsonarray2.getJSONObject(jsonarray2.length() - 1);
ItemName6 = finalObject7.getString("name");
//Highest win names
JSONObject finalObject8 = jsonarray3.getJSONObject(jsonarray3.length() - 6);
ItemNameHW = finalObject8.getString("name");
JSONObject finalObject9 = jsonarray3.getJSONObject(jsonarray3.length() - 5);
ItemName2HW = finalObject9.getString("name");
JSONObject finalObject10 = jsonarray3.getJSONObject(jsonarray3.length() - 4);
ItemName3HW = finalObject10.getString("name");
JSONObject finalObject11 = jsonarray3.getJSONObject(jsonarray3.length() - 3);
ItemName4HW = finalObject11.getString("name");
JSONObject finalObject12 = jsonarray3.getJSONObject(jsonarray3.length() - 2);
ItemName5HW = finalObject12.getString("name");
JSONObject finalObject13 = jsonarray3.getJSONObject(jsonarray3.length() - 1);
ItemName6HW = finalObject13.getString("name");
layoutmodel.setItem1(ItemName);
layoutmodel.setItem2(ItemName2);
layoutmodel.setItem3(ItemName3);
layoutmodel.setItem4(ItemName4);
layoutmodel.setItem5(ItemName5);
layoutmodel.setItem6(ItemName6);
layoutmodel.setItem1HW(ItemNameHW);
layoutmodel.setItem2HW(ItemName2HW);
layoutmodel.setItem3HW(ItemName3HW);
layoutmodel.setItem4HW(ItemName4HW);
layoutmodel.setItem5HW(ItemName5HW);
layoutmodel.setItem6HW(ItemName6HW);
layoutmodel.setRole(role);
layoutmodel.setChampionName2(ChampionName);
layoutmodel.setChamppos(champpos);
LayoutModelList.add(layoutmodel);
}
return LayoutModelList;
} catch (JSONException | IOException e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
#Override
protected void onPostExecute(List<Layoutmodel> result) {
super.onPostExecute(result);
LayoutAdapter adapter2 = new LayoutAdapter(getApplicationContext(), R.layout.rows, result);
Champ.setAdapter(adapter2);
}
}
public class LayoutAdapter extends ArrayAdapter {
private List<Layoutmodel> LayoutModelList2;
private int resource;
private LayoutInflater inflater;
public LayoutAdapter(Context context2, int resource, List<Layoutmodel> objects) {
super(context2, resource, objects);
LayoutModelList2 = objects;
this.resource = resource;
inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
}
#Override
public View getView(int position2, View convertView2, ViewGroup parent2) {
ViewHolder holder = null;
if (convertView2 == null) {
holder = new ViewHolder();
convertView2 = inflater.inflate(resource, null);
holder.nameofchamp = (TextView) convertView2.findViewById(R.id.textView);
holder.position = (TextView) convertView2.findViewById(R.id.smalltxt);
holder.Champposition = (TextView) convertView2.findViewById(R.id.textView17);
String ItemNameInLowerCase;
String ItemName2InLowerCase;
String ItemName3InLowerCase;
String ItemName4InLowerCase;
String ItemName5InLowerCase;
String ItemName6InLowerCase;
String ItemName2InLowerCaseHW;
String ItemName3InLowerCaseHW;
String ItemName4InLowerCaseHW;
String ItemName5InLowerCaseHW;
String ItemName6InLowerCaseHW;
holder.Champitemimg1 = (ImageView) convertView2.findViewById(R.id.imageView7);
holder.Champitemimg2 = (ImageView) convertView2.findViewById(R.id.imageView6);
holder.Champitemimg3 = (ImageView) convertView2.findViewById(R.id.imageView5);
holder.Champitemimg4 = (ImageView) convertView2.findViewById(R.id.imageView4);
holder.Champitemimg5 = (ImageView) convertView2.findViewById(R.id.imageView3);
holder.Champitemimg6 = (ImageView) convertView2.findViewById(R.id.imageView2);
holder.Champitemimg1HW = (ImageView) convertView2.findViewById(R.id.imageView8);
holder.Champitemimg2HW = (ImageView) convertView2.findViewById(R.id.imageView9);
holder.Champitemimg3HW = (ImageView) convertView2.findViewById(R.id.imageView10);
holder.Champitemimg4HW = (ImageView) convertView2.findViewById(R.id.imageView11);
holder.Champitemimg5HW = (ImageView) convertView2.findViewById(R.id.imageView12);
holder.Champitemimg6HW = (ImageView) convertView2.findViewById(R.id.imageView13);
ImageView imgtesta;
String ChampionNameinlower;
imgtesta = (ImageView) convertView2.findViewById(R.id.imageView);
ChampionNameinlower = ChampionName.toLowerCase().replaceAll("'", "").replaceAll(" ", "");
int id10 = getResources().getIdentifier("com.example.kripzy.url:drawable/" + ChampionNameinlower + "_square_0", null, null);
imgtesta.setImageResource(id10);
holder.champitem1 = (TextView) convertView2.findViewById(R.id.textView9);
holder.champitem2 = (TextView) convertView2.findViewById(R.id.textView8);
holder.champitem3 = (TextView) convertView2.findViewById(R.id.textView7);
holder.champitem4 = (TextView) convertView2.findViewById(R.id.textView6);
holder.champitem5 = (TextView) convertView2.findViewById(R.id.textView5);
holder.champitem6 = (TextView) convertView2.findViewById(R.id.textView4);
holder.champitem1HW = (TextView) convertView2.findViewById(R.id.textView10);
holder.champitem2HW = (TextView) convertView2.findViewById(R.id.textView11);
holder.champitem3HW = (TextView) convertView2.findViewById(R.id.textView12);
holder.champitem4HW = (TextView) convertView2.findViewById(R.id.textView13);
holder.champitem5HW = (TextView) convertView2.findViewById(R.id.textView14);
holder.champitem6HW = (TextView) convertView2.findViewById(R.id.textView15);
holder.nameofchamp.setText(LayoutModelList2.get(position2).getChampionName2());
holder.position.setText(LayoutModelList2.get(position2).getRole());
holder.Champposition.setText(LayoutModelList2.get(position2).getChamppos());
holder.champitem1.setText(LayoutModelList2.get(position2).getItem1());
holder.champitem2.setText(LayoutModelList2.get(position2).getItem2());
holder.champitem3.setText(LayoutModelList2.get(position2).getItem3());
holder.champitem4.setText(LayoutModelList2.get(position2).getItem4());
holder.champitem5.setText(LayoutModelList2.get(position2).getItem5());
holder.champitem6.setText(LayoutModelList2.get(position2).getItem6());
holder.champitem1HW.setText(LayoutModelList2.get(position2).getItem1HW());
holder.champitem2HW.setText(LayoutModelList2.get(position2).getItem2HW());
holder.champitem3HW.setText(LayoutModelList2.get(position2).getItem3HW());
holder.champitem4HW.setText(LayoutModelList2.get(position2).getItem4HW());
holder.champitem5HW.setText(LayoutModelList2.get(position2).getItem5HW());
holder.champitem6HW.setText(LayoutModelList2.get(position2).getItem6HW());
ItemNameInLowerCase = ItemName.toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName2InLowerCase = ItemName2.toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName3InLowerCase = ItemName3.toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName4InLowerCase = ItemName4.toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName5InLowerCase = ItemName5.toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName6InLowerCase = ItemName6.toLowerCase().replaceAll("'", "").replaceAll(" ", "");
String itemNameInLowerCaseHW = ItemNameHW.toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName2InLowerCaseHW = ItemName2HW.toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName3InLowerCaseHW = ItemName3HW.toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName4InLowerCaseHW = ItemName4HW.toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName5InLowerCaseHW = ItemName5HW.toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName6InLowerCaseHW = ItemName6HW.toLowerCase().replaceAll("'", "").replaceAll(" ", "");
int id = getResources().getIdentifier("com.example.kripzy.url:drawable/" + ItemNameInLowerCase, null, null);
holder.Champitemimg1.setImageResource(id);
int id2 = getResources().getIdentifier("com.example.kripzy.url:drawable/" + ItemName2InLowerCase, null, null);
holder.Champitemimg2.setImageResource(id2);
int id3 = getResources().getIdentifier("com.example.kripzy.url:drawable/" + ItemName3InLowerCase, null, null);
holder.Champitemimg3.setImageResource(id3);
int id4 = getResources().getIdentifier("com.example.kripzy.url:drawable/" + ItemName4InLowerCase, null, null);
holder.Champitemimg4.setImageResource(id4);
int id5 = getResources().getIdentifier("com.example.kripzy.url:drawable/" + ItemName5InLowerCase, null, null);
holder.Champitemimg5.setImageResource(id5);
int id6 = getResources().getIdentifier("com.example.kripzy.url:drawable/" + ItemName6InLowerCase, null, null);
holder.Champitemimg6.setImageResource(id6);
int idHW = getResources().getIdentifier("com.example.kripzy.url:drawable/" + itemNameInLowerCaseHW, null, null);
holder.Champitemimg1HW.setImageResource(idHW);
int id2HW = getResources().getIdentifier("com.example.kripzy.url:drawable/" + ItemName2InLowerCaseHW, null, null);
holder.Champitemimg2HW.setImageResource(id2HW);
int id3HW = getResources().getIdentifier("com.example.kripzy.url:drawable/" + ItemName3InLowerCaseHW, null, null);
holder.Champitemimg3HW.setImageResource(id3HW);
int id4HW = getResources().getIdentifier("com.example.kripzy.url:drawable/" + ItemName4InLowerCaseHW, null, null);
holder.Champitemimg4HW.setImageResource(id4HW);
int id5HW = getResources().getIdentifier("com.example.kripzy.url:drawable/" + ItemName5InLowerCaseHW, null, null);
holder.Champitemimg5HW.setImageResource(id5HW);
int id6HW = getResources().getIdentifier("com.example.kripzy.url:drawable/" + ItemName6InLowerCaseHW, null, null);
holder.Champitemimg6HW.setImageResource(id6HW);
convertView2.setTag(holder);
}
else{
holder = (ViewHolder) convertView2.getTag();
}
return convertView2;
}
Newly added holder;
TextView nameofchamp;
TextView position;
TextView Champposition;
TextView champitem1;
TextView champitem2;
TextView champitem3;
TextView champitem4;
TextView champitem5;
TextView champitem6;
TextView champitem1HW;
TextView champitem2HW;
TextView champitem3HW;
TextView champitem4HW;
TextView champitem5HW;
TextView champitem6HW;
ImageView Champitemimg1;
ImageView Champitemimg2;
ImageView Champitemimg3;
ImageView Champitemimg4;
ImageView Champitemimg5;
ImageView Champitemimg6;
ImageView Champitemimg1HW;
ImageView Champitemimg2HW;
ImageView Champitemimg3HW;
ImageView Champitemimg4HW;
ImageView Champitemimg5HW;
ImageView Champitemimg6HW;
}
}
When i put a log.v at the bottom of the code, it always replies this
05-21 14:41:40.646 4536-4536/com.example.kripzy.url V/Where is my error: enchantment:bloodrazor
05-21 14:41:40.659 4536-4536/com.example.kripzy.url V/Where is my error: enchantment:bloodrazor
So what i was doing wrong was i was just using a string which just contained the information from the last entry on the listview, hence why it was only showing the images from it, so to fix this i had to change it to the following;
ItemNameInLowerCase = holder.champitem1.getText().toString().toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName2InLowerCase = holder.champitem2.getText().toString().toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName3InLowerCase = holder.champitem3.getText().toString().toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName4InLowerCase = holder.champitem4.getText().toString().toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName5InLowerCase = holder.champitem5.getText().toString().toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName6InLowerCase = holder.champitem6.getText().toString().toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemNameInLowerCaseHW = holder.champitem1HW.getText().toString().toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName2InLowerCaseHW = holder.champitem2HW.getText().toString().toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName3InLowerCaseHW = holder.champitem3HW.getText().toString().toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName4InLowerCaseHW = holder.champitem4HW.getText().toString().toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName5InLowerCaseHW = holder.champitem5HW.getText().toString().toLowerCase().replaceAll("'", "").replaceAll(" ", "");
ItemName6InLowerCaseHW = holder.champitem6HW.getText().toString().toLowerCase().replaceAll("'", "").replaceAll(" ", "");

how to use two delimiters for StringTokenizer in android

Hi everybody, I stucked in how to use two delimiters in
StringTokenizer in android for storing null values into db I have
string like this, string1=IMPS 2223 9481851276 7654321 , , 33
But empty fields missing in when used stringtokeniser
I want store result in db like this,
IMPS
2223
9481851276
7654321
null
null
33
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.getactivity_layout);
LinearLayout layout = (LinearLayout) findViewById(R.id.details);
sms = getIntent().getStringExtra("value");
merchantName = getIntent().getStringExtra("merchantName");
tv = (TextView) findViewById (R.id.textview_getactivity_key);
tv.setText("Enter the Detail for-"+merchantName);
keyText = (EditText) findViewById(R.id.edittext_getactivity_value);
//finalKey = "Pay"+" "+merchantName+"-";
keyText.setText(finalKey);
View submitButton = findViewById(R.id.finish);
inputMap = new LinkedHashMap<String, EditText>();
Pattern p = Pattern.compile("\\|.*?\\|");
Matcher m = p.matcher(sms);
while (m.find())
{
//String to be replaced
String s = m.group(0);
Log.d("TestTag", "Value of string in getdetails"+s);
if (!" ".equals(s.replaceAll("\\|", "")))
{
TextView t = new TextView(this);
t.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
t.setText(s.replaceAll("\\|", ""));
t.setPadding(0, 0, 0, 5);
t.setTextColor(getResources().getColor(android.R.color.black));
EditText et = new EditText(this);
et.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
//et.setInputType(1234);
layout.addView(t);
layout.addView(et);
inputMap.put(s, et);
}
}
submitButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
keyValue = keyText.getText().toString().trim();
ArrayList<String> tempArray = new ArrayList<String>();
String string=null;
if(sms != null && inputMap != null){
for(String s : inputMap.keySet()){
String inputValue = inputMap.get(s).getText().toString().trim();
if(inputValue.equalsIgnoreCase("") || inputValue.equals(null)){
//showDialog(s.replaceAll("\\|", "")+ " is mandatory.", inputMap.get(s));
return;
//sms = sms.replace(s, inputValue);
//tempArray.add(sms.replace(s, inputValue));
}
else{
sms = sms.replace(s, inputValue);
tempArray.add(sms.replace(s, inputValue));
}
string = sms.replaceAll("\\|\\s\\|",",");
}
StringTokenizer tokens = new StringTokenizer(string, " ");
String first = tokens.hasMoreTokens() ? tokens.nextToken() : null;
String second =tokens.hasMoreTokens() ? tokens.nextToken() : null;
String third = tokens.hasMoreTokens() ? tokens.nextToken() : null;
String fourth =tokens.hasMoreTokens() ? tokens.nextToken() : null;
String fifth = tokens.hasMoreTokens() ? tokens.nextToken() : null;
String sixth = tokens.hasMoreTokens() ? tokens.nextToken() : null;
String seventh =tokens.hasMoreTokens() ? tokens.nextToken() : null;
Log.d("Test123", "Split String is : "+first+" "+second+" "+third+" "+fourth+" "+fifth+" "+sixth+" "+seventh);
in.setKeyValue(keyValue);
in.setSmsKeyword(first);
in.setCustomerAccountNo(second);
in.setMobileNo(third);
in.setMmid(fourth);
in.setAmount(fifth);
in.setCustomerPin(sixth);
in.setRemarks(seventh);
in.setTempName(merchantName);
accessDB.open();
accessDB.insertMerchant(in);
accessDB.close();
Intent detailsIntent = new Intent(GetDetailsActivity.this,MainScreenTab.class);
detailsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(detailsIntent);
}

How to get tablerow id dynamically in android?

Hello, my old code is working, but the problem is that when i am clicking tablerow it call another activty, but it not set that table row data but it setting last array data to that activity.
Means it set the last array value to next screen activity.
for ( j = 0; j < dataListfeture.size(); j++)
{
HashMap<String, String> hm = new HashMap<String, String>();
hm = dataListfeture.get(j);
final TableRow tblrow = new TableRow(MainScreen.this);
final View rowView = inflater.inflate(R.layout.featuredrow, null);
tblrow.setId(j);
tblrow.getId();
featuredName = (TextView) rowView.findViewById(R.id.xxName);
featuredDistance = (TextView) rowView.findViewById(R.id.xxDistance);
featuredVeneType = (TextView) rowView.findViewById(R.id.xxVeneType);
featuredPhone = (TextView) rowView.findViewById(R.id.xxPhone);
featuredAddress = (TextView) rowView.findViewById(R.id.xxAddress);
Drawable image = ImageOperations(MainScreen.this, hm.get("url"), "image.jpg");
featuredImage = (ImageView) rowView.findViewById(R.id.xxdImage);
featuredImage.setImageDrawable(image);
featuredName.setText("" + hm.get("name"));
featuredDistance.setText("" + hm.get("distance") + " mi");
featuredVeneType.setText("" + hm.get("venuetype"));
featuredPhone.setText("" + hm.get("phonenumber"));
featuredAddress.setText("" + hm.get("address"));
mapnamelist = hm.get("name");
mapvenuelist = hm.get("venuetype");
mapothervenuelist = hm.get("othervenuetype");
mapaddresslist= hm.get("address");
mapcitylist= hm.get("city");
mapstatelist= hm.get("state");
tblrow.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
final ProgressDialog progDailog = ProgressDialog.show(MainScreen.this, null, "Loading ....", true);
final Handler handler = new Handler()
{
public void handleMessage(Message msg)
{
System.out.println("search");
Intent myIntent = new Intent(MainScreen.this, xxxxscreen.class);
startActivity(myIntent);
MainScreen.this.finish();
progDailog.dismiss();
}
};
new Thread()
{
public void run()
{
try
{
System.out.println();
handler.sendEmptyMessage(1);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}.start();
}
});
Create an int array of id say array_id[] and after setting id to table row add that id to array_id[] also like
tblrow.setId(j);
array_id[j] = j;
And in onClick method do this:
for(int i = 0;i< array_id.length;i++)
{
TableRow tbl_row = (TableRow) findViewById(i);
if(v.getId() == array_id[i])
{
/** Perform your Operations */
}
}

Categories

Resources