I have a ListView that utilizes a CheckedTextView and a clear all button that has the following code:
btnClearAll.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int listsize = songsList.size();
filelv = (ListView)getView().findViewById(R.id.FileList);
checkedCount = 0;
for (int i=0; i<listsize-1; i++) {
// if(currentPlayList.get(i).equals ("Checked")){
songsList.get(i).get("songCheckedStatus").equals("Not Checked");
filelv.setItemChecked(i, false);
}
}
});
When the code executes, each array "songsList" value is set to "Not Checked" correctly, so I know that the button is working. However, the CheckedTextView items are not "unticking".
Where am I going wrong?
olution:
As mentioned above, I just set up a global variable and passed whether I wanted to Select All or Clear All to it. Then I just called my function for populating the ListView. As the ListView is built, it checks the variable in a simple "if" statement, and adds whether to check or uncheck. The cursor adapter then does the check/uncheck as it reruns.
//The code for clearing all.
btnClearAll.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
checkedCount = 0;
GetMusicMode = "ClearAll";
GetMusic getMusic = new GetMusic();
getMusic.execute();
}
});
And this from my data grabber for the ListView.
....
String track_Title = null;
String track_Path = null;
String track_Artist = null;
String track_Album = null;
String track_ID = null;
String track_TrackNumber = null;
String track_AlbumID = null;
String track_ArtistID = null;
String track_Checked = null;
if (Constants.GetMusicMode.equals("SelectAll")){
track_Checked = "Checked";
}else{
track_Checked = "Not Checked";
}
.....
.....
HashMap<String, String> song = new HashMap<String, String>();
song.put("songTitle", track_Title);
song.put("songPath", track_Path);
song.put("songArtist", track_Artist);
song.put("songAlbum", track_Album);
song.put("songTrackNumber", track_TrackNumber);
song.put("songID", track_ID);
song.put("songAlbumID", track_AlbumID);
song.put("songArtistID", track_ArtistID);
song.put("songCheckedStatus", track_Checked);
// Adding each song to SongList
songsList.add(song);
....throw to cursor adapter
and finally, this section from the cursoradapter getview
if (songsList.get(position).get("songCheckedStatus").equals("Checked")){
holder.checkTextView.setChecked(true);
}else{
holder.checkTextView.setChecked(false);
}
Related
int size = mcq.size();
String arr[] = null;
int i;
{
for (i = 0; i < size; i++) {
if (op1.isPressed()) {
arr[i] = tv1.getText().toString();
// Log.e("Array",arr[i]);
} else if (op2.isPressed()) {
arr[i] = tv2.getText().toString();
//Log.e("Array",arr[i]);
} else if (op3.isPressed()) {
arr[i] = tv3.getText().toString();
// Log.e("Array",arr[i]);
} else if (op4.isPressed()) {
arr[i] = tv4.getText().toString();
//Log.e("Array",arr[i]);
}
I am trying to store the data in an array when the button is pressed,but it always shows null.And when the for loop is over I want to display my array.
here , Arrays in Java have a size so u cannot do like this. Instead of this
use list,
ArrayList<String> arr = new ArrayList<String>();
Inorder to do using String array :
String[] arr = new String[SIZEDEFNE HERE];
For ur answer :
ArrayList<String> arr = new ArrayList<String>();
int i;
{
for (i = 0; i < size; i++) {
if (op1.isPressed()) {
arr.add(tv1.getText().toString());
} else if (op2.isPressed()) {
arr.add(tv2.getText().toString());
} else if (op3.isPressed()) {
arr.add(tv3.getText().toString());
} else if (op4.isPressed()) {
arr.add(tv4.getText().toString());
}
Retrive value using
String s = arr.get(0);
This is because your string array is null. Declare it with the size as
String[] arr = new String[size];
Try Array List. use the following code in your main java
final ArrayList<String> list = new ArrayList<String>();
Button button= (Button) findViewById(R.id.buttonId);
final EditText editText = (EditText) findViewById(R.id.editTextId)
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
list.add(editText.getText().toString());
}
});
To avoid duplication in arraylist .You can use arraylist for faster then String array
ArrayList<String> list = new ArrayList<String>();
list.add("Krishna");
list.add("Krishna");
list.add("Kishan");
list.add("Krishn");
list.add("Aryan");
list.add("Harm");
System.out.println("List"+list);
HashSet hs = new HashSet();
hs.addAll(list);
list.clear();
list.addAll(hs);
I have a listview with a custom adapter of two lines(textview) and one checkbox.
I would like to save the state of the checkbox when I close the app, but I don't know how, I tried many things but nothing!
I can do it with a android.R.layout.simple_list_item_multiple_choice but no with my adapter.
onCreate
private SimpleAdapter notes;
ArrayList<HashMap<String, String>> arraylist_hashmap = new ArrayList<HashMap<String, String>>();
if (lenguage.equals("Deutsch")) {
HashMap<String, String> item;
for (int i = 0; i < StatesAndCapitalsAleman.length; i++) {
item = new HashMap<String, String>();
item.put("line1", StatesAndCapitalsAleman[i][0]);
item.put("line2", StatesAndCapitalsAleman[i][1]);
arraylist_hashmap.add(item);
}
notes = new SimpleAdapter(this, arraylist_hashmap, R.layout.main_item_two_line_row,
new String[] { "line1", "line2" },
new int[] { R.id.text1, R.id.text2 });
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
setListAdapter(notes);
Save state
#Override
public void onBackPressed() {
// TODO Auto-generated method stub
SaveSelections();
super.onBackPressed();
}
private void SaveSelections() {
// save the selections in the shared preference in private mode for the
// user
SharedPreferences.Editor prefEditor = sharedpreferences.edit();
String savedItems = getSavedItems();
prefEditor.putString(MyPREFERENCES.toString(), savedItems);
prefEditor.commit();
}
private String getSavedItems() {
String savedItems = "";
int count = this.listView_ale.getAdapter().getCount();
for (int i = 0; i < count; i++) {
if (this.listView_ale.isItemChecked(i)) {
if (savedItems.length() > 0) {
savedItems += "," + this.listView_ale.getItemAtPosition(i);
} else {
savedItems += this.listView_ale.getItemAtPosition(i);
}
}
}
return savedItems;
}
You need to create an create an custom adapter with your own model with.
Create model which has a selected boolean field an other fields as per your requirement. And then create a custom adapter for your list. and then you can modify the model object on the checkbox's check state as selected true/false and latter you can save the sate as per your requirement.
I want to the change the text of the button which was clicked in a getView function. The text is changed but when the view is scrolled the text of other buttons which the same id is also changed. I don't want that. I want only the text of the button which was clicked to be changed.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final int i=position;
List dialog = DialogList.get(i);
final Object memid = dialog.get(2).toString();
final String dialogid = dialog.get(3).toString();
final String dialogtype = dialog.get(4).toString();
ImageView imageViews;
if (convertView == null) {
LayoutInflater layoutInflator = LayoutInflater.from(getContext());
convertView = layoutInflator.inflate(R.layout.invite_friends_list, null);
holder = new ViewHolder();
holder.friendsname = (TextView) convertView.findViewById(R.id.friendsname);
holder.profimage = (ImageView) convertView.findViewById(R.id.member_image);
holder.assign = (Button) convertView.findViewById(R.id.btnInvite);
convertView.setTag(holder);
}
holder = (ViewHolder) convertView.getTag();
holder.friendsname.setText(user_name);
holder.assign.setTag(holder);
holder.assign.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.d("assigntext", holder.assign.getText().toString());
SharedPreferences prfs = _context.getSharedPreferences("MyPref",
Context.MODE_PRIVATE);
String token = prfs.getString("apptoken", "");
String url = null;
if(dialogtype.equals("V"))
{
url = "http://www.jjhjjkh.com/index.php?/alkjlkjlk/dialog/invjlkjlkjklialogmember?apptoken="
+ token + "&dialogid=" + dialogid+"&mid="+memid.toString();
}
if(dialogtype.equals("P"))
{
url = "http://www.ckjhuihiuhiu.com/index.php?/kjij/dialog/inviuhuihuihuimember?apptoken="
+ token + "&dialogid=" + dialogid+"&mid="+memid.toString();
}
List<String> urlList = new ArrayList<String>();
Log.d("cat",url.toString());
// JSON Node names
String TAG_DETAILS = "invitemembers";
String TAG_MSG = "msg";
// contacts JSONArray
JSONArray dialogpublish = null;
JSONArray dialogs = null;
// Creating JSON Parser instance
JSONParser jParser = new JSONParser();
// getting JSON string from URL
JSONObject json = jParser.getJSONFromUrl(url);
// Log.d("cat",json.toString());
try {
dialogpublish = json.getJSONArray(TAG_DETAILS);
// Log.d("apptoken",login.toString());
for (int i = 0; i < dialogpublish.length(); i++) {
JSONObject d = dialogpublish.getJSONObject(i);
String msg = d.getString(TAG_MSG);
//dialogs = d.getJSONArray("updatedialog");
if (msg.equals("success")) {
// ViewHolder mH = (ViewHolder)view.getTag();
//Integer currentPos = view.getTag();
String mem_id= view.getTag().toString();
if(mem_id.equals(memid))
{
Toast.makeText(_context, "Member invited Succesfully",Toast.LENGTH_LONG).show();
ViewHolder mH = (ViewHolder)view.getTag();
mH.assign.setText("Invited");
}
//view.setText("Invited");
}
}
} catch (JSONException e) {
e.printStackTrace();
}
I guess that is happenning because you are using the viewholder pattern. The viewholder pattern tends to cache views for performance optimization. try to write the adapter without using viewholder. If the list view items arent large in numbers.
Create a new HashMap in Adapter :
private HashMap<Integer, String> buttonTitleMap=new HashMap<Integer, String>();
Create a function getButtonTitle as below in Adapter :
private String getButtonTitle(int position){
if(buttonTitleMap.containsKey(position)){
return buttonTitleMap.get(position);
}else{
return "Your Normal Button text";
}
}
Then in getView() of Adapter, befor returning convertView, call :
....
holder.assign.setText(getButtonTitle(position));
holder.friendsname.setTag(position);
return convertView;
}
When the Button is clicked, you can get the list item position of the button. So what you need to do is to change the button title as you do before and also update the hashmap with the same value :
holder.assign.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
....
mH.assign.setText("Invited");
int position = (int)mH.friendsname.getTag();
buttonTitleMap.put(position,"Invited");
....
}
}
You are done.
Try
String mem_id= view.getTag().toString();
if(mem_id.equals(memid))
{
Toast.makeText(_context, "Member invited Succesfully",Toast.LENGTH_LONG).show();
((Button)view).setText("Invited");
}
i don't know how to make a function to show the next/previous detail data by clicking the next/previous button based on listview.
This is the screenshot that i want to do
My listview Activity
My Detail data Activity, to show next/previous data from listview
EDIT : i have a listview data (use xml parser), and pass the data to new acitivity called "Detail_toko.class" :
List<NameValuePair> paramemeter = new ArrayList<NameValuePair>();
paramemeter.add(new BasicNameValuePair("keyword", "a"));
// paramemeter.add(new BasicNameValuePair("kategori",Category.getSelectedItem().toString()));
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL, paramemeter); // getting XML from URL
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(TAG_DETAIL);
// looping through all song nodes <song>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(TAG_ID, parser.getValue(e, TAG_ID));
map.put(TAG_NAMATOKO, parser.getValue(e, TAG_NAMATOKO));
map.put(TAG_KATEGORI, parser.getValue(e, TAG_KATEGORI));
map.put(TAG_EMAIL, parser.getValue(e, TAG_EMAIL));
map.put(TAG_ICON, parser.getValue(e, TAG_ICON));
// adding HashList to ArrayList
PremiumList.add(map);
}
return null;
}
/**
* Updating parsed JSON data into ListView
* */
list=(ListView)findViewById(R.id.listview);
if(PremiumList.size() > 0)
{
adapter=new LazyAdapterStore(ListPerusahaan.this, PremiumList);
list.setAdapter(adapter);
}
else
{
Toast toast= Toast.makeText(getApplicationContext(), "No data found, enter another keyword", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
}
// Click event for single list row
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String nama_toko = ((TextView) view.findViewById(R.id.nama_toko)).getText().toString();
String kategori = ((TextView) view.findViewById(R.id.kategori)).getText().toString();
String email = ((TextView) view.findViewById(R.id.email)).getText().toString();
PremiumList = new ArrayList<HashMap<String, String>>();
Intent in = new Intent(ListPerusahaan.this, Detail_toko.class);
in.putExtra("PremiumList", PremiumList);
//in.putStringArrayListExtra( "PremiumList", PremiumList );
in.putExtra("position", position);
in.putExtra("TotalData", TotalData);
in.putExtra(TAG_NAMATOKO, nama_toko);
in.putExtra(TAG_KATEGORI, kategori);
in.putExtra(TAG_EMAIL, email);
startActivity(in);
This is my LazyAdapterStore code :
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_data_store, null);
TextView nama_toko = (TextView)vi.findViewById(R.id.nama_toko); // title
TextView kategori = (TextView)vi.findViewById(R.id.kategori); // title
ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image
TextView email = (TextView)vi.findViewById(R.id.email); // artist name
HashMap<String, String> detail = new HashMap<String, String>();
detail = data.get(position);
// Setting all values in listview
nama_toko.setText(detail.get(ListPerusahaan.TAG_NAMATOKO));
kategori.setText(detail.get(ListPerusahaan.TAG_KATEGORI));
email.setText(detail.get(ListPerusahaan.TAG_EMAIL));
imageLoader.DisplayImage(detail.get(ListPerusahaan.TAG_ICON), thumb_image);
return vi;
}
EDIT : and, this is my new activity "Detail_Toko" to display detail data from listview items :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//this must be called BEFORE setContentView
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.detail_toko);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
call_btn=(Button)findViewById(R.id.call);
email_btn=(Button)findViewById(R.id.email);
sms_btn=(Button)findViewById(R.id.sms);
Next_btn=(Button)findViewById(R.id.Next);
Prev_btn=(Button)findViewById(R.id.Prev);
phonenumber=(TextView)findViewById(R.id.telpon);
// getting intent data
Intent in = getIntent();
// #SuppressWarnings("unchecked")
//ArrayList<HashMap<String, String>> PremiumList = (ArrayList<HashMap<String, String>>) getIntent().getSerializableExtra("PremiumList");
// Get String values from previous intent
final String nama_toko = in.getStringExtra(TAG_NAMATOKO);
final String kategori = in.getStringExtra(TAG_KATEGORI);
final String email = in.getStringExtra(TAG_EMAIL);
// Get Int values from previous intent
final int posisi = in.getExtras().getInt("position");
final int Total_data = in.getExtras().getInt("TotalData");
/*
Bundle bundle = in.getExtras();
HashMap<String, String> list = (HashMap<String, String>) bundle.getSerializable("PremiumList");
list = data.get(currentposition);
*/
Bundle bundle = in.getExtras();
HashMap<String, String> list = (HashMap<String, String>) bundle.getSerializable("PremiumList");
list = data.get(currentposition);
// Displaying all values on the screen
lblPosisi = (TextView) findViewById(R.id.namatoko);
lbltotaldata = (TextView) findViewById(R.id.nama);
lblNamatoko = (TextView) findViewById(R.id.nama_toko);
lblKategori = (TextView) findViewById(R.id.kategori);
lblEmail = (TextView) findViewById(R.id.textemail);
lblPosisi.setText(String.valueOf(posisi));
lbltotaldata.setText(String.valueOf(Total_data));
lblNamatoko.setText(nama_toko);
lblKategori.setText(kategori);
lblEmail.setText(email);
// Set the int value of currentposition from previous selected listview item
currentposition = posisi;
Next_btn.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
if(currentposition >= Total_data - 1)
{
Toast toast= Toast.makeText(getApplicationContext(), "Last Record", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
}
else
{
currentposition++;
lblPosisi.setText(String.valueOf(currentposition));
lblNamatoko.setText(list.get(nama_toko));
lblKategori.setText(list.get(kategori));
lblEmail.setText(list.get(email));
}
}
});
Prev_btn.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
if(currentposition <= 0)
{
Toast toast= Toast.makeText(getApplicationContext(), "First Record", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
}
else
{
currentposition--;
lblPosisi.setText(String.valueOf(currentposition));
lblNamatoko.setText(list.get(nama_toko));
lblKategori.setText(list.get(kategori));
lblEmail.setText(list.get(email));
}
}
});
the problem is, i don't know how to make a function to show the next/previous detail data from listview by clicking the next/previous button in "Detail_toko" activity.
Please someone Help me...
Thank in advance
Just seen your request on last post.
Solution given by Parvaz is perfect, you just need to figure out the code.
You have an arraylist "PremiumList" which is responsible for your listview rows data.
All you need is to pass position and this list to Detail_toko.class (via intent using parceable or declaring arraylist as static (not recommended) etc. ) and your solution will be couple of steps away.
In Detail_toko.class create a global variable currentPosition which will get its value from past activity like TAG_NAMATOKO from intent.
Then in onClickListener of NEXT button increment 1 to currentPosition and get detail from your arraylist you have just transported from last activity as you have done in your getView method.
HashMap<String, String> detail = new HashMap<String, String>();
detail = data.get(currentPosition);
// Setting all values in listview
nama_toko = detail.get(ListPerusahaan.TAG_NAMATOKO);
kategori = detail.get(ListPerusahaan.TAG_KATEGORI);
email = detail.get(ListPerusahaan.TAG_EMAIL);
Set these values and your new view will be updated accordingly.
In onClickListener of PREVIOUS button decrement 1 from currentPosition, followed by same code (which means you must create a method and call that, no code repetition).
Try it. This is as detailed as we can explain without actually doing your homework !
EDIT :
First of all remove this line from OnItemClick
PremiumList = new ArrayList<HashMap<String, String>>();
You are clearing all the data from PremiumList in this line and this way you will get blank list in next activity. So get rid of this line.
Once you will get PremiumList in your next activity, all you need is position and totalData along with it in intent extra.
You can get rid of TAG_NAMATOKO, TAG_KATEGORI,TAG_EMAIL from your intent extra.
I had told you to not to repeat the code, as you are beginner it is very important for you to follow as it will make your life easy by
taking such considerations and making your habbit.
Now your code in "Detail_Toko" will become:
HashMap<String, String> list = null;
int currentposition = 0;
int Total_data =0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//this must be called BEFORE setContentView
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.detail_toko);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
call_btn=(Button)findViewById(R.id.call);
email_btn=(Button)findViewById(R.id.email);
sms_btn=(Button)findViewById(R.id.sms);
Next_btn=(Button)findViewById(R.id.Next);
Prev_btn=(Button)findViewById(R.id.Prev);
phonenumber=(TextView)findViewById(R.id.telpon);
// Displaying all values on the screen
lblPosisi = (TextView) findViewById(R.id.namatoko);
lbltotaldata = (TextView) findViewById(R.id.nama);
lblNamatoko = (TextView) findViewById(R.id.nama_toko);
lblKategori = (TextView) findViewById(R.id.kategori);
lblEmail = (TextView) findViewById(R.id.textemail);
// getting intent data
Bundle bundle = getIntent().getExtras();
// Get Int values from previous intent
currentposition = bundle.getInt("position");
Total_data = bundle.getInt("TotalData");
list = (HashMap<String, String>) bundle.get("PremiumList");
setView();
Next_btn.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
if(currentposition >= Total_data - 1)
{
Toast toast= Toast.makeText(getApplicationContext(), "Last Record", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
}
else
{
currentposition++;
setView();
}
}
});
Prev_btn.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
if(currentposition <= 0)
{
Toast toast= Toast.makeText(getApplicationContext(), "First Record", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
}
else
{
currentposition--;
setView();
}
}
});
private void setView()
{
if(list != null && list.size() > currentposition)
{
HashMap<String, String> detail = new HashMap<String, String>();
detail = list.get(currentposition);
lblPosisi.setText(String.valueOf(currentposition));
lbltotaldata.setText(String.valueOf(Total_data));
lblNamatoko.setText(detail.get(ListPerusahaan.TAG_NAMATOKO));
lblKategori.setText(detail.get(ListPerusahaan.TAG_KATEGORI));
lblEmail.setText(detail.get(ListPerusahaan.TAG_EMAIL));
}
}
Suggestion: Use ViewHolder to populate view in getView Method, it will make your adapter "An efficent adapter". (search for examples)
Follow naming convention and all.
Check anyObject != null , their size or length before using them and bundle.containKey etc stuff to avoid fatal exception like nullPointerException.
Just pass the PremiumList ArrayList to your Detail_toko Activity...either pass it by Intent or get it directly from the getter methods. Then in your Detail_toko activity on each next / previous button click increment the position of arraylist to get the data and then populate accordingly.
This is how you will pass your arraylist
Passing ArrayList through Intent
and instead of getting the rest of the data from intent get the data from the arraylist.
like arraylist.get(index).
just like this
/********Instead of getting your values like this*******************/
String nama_toko = in.getStringExtra(TAG_NAMATOKO);
String kategori = in.getStringExtra(TAG_KATEGORI);
String email = in.getStringExtra(TAG_EMAIL);
/************************Use a method like given here How to do the next button action?****************************/
//The method setvalue would be quite useful for you where you will pass the int j parameter to get appropriate values. If next button is clicked increment the j if previous button is clicked decrement it. and then display your values asusual.
// Displaying all values on the screen
lblNamatoko = (TextView) findViewById(R.id.namatoko);
lblKategori = (TextView) findViewById(R.id.kategori);
lblEmail = (TextView) findViewById(R.id.textemail);
lblNamatoko.setText(nama_toko);
lblKategori.setText(kategori);
lblEmail.setText(email);
I have some problem in updating the values to hash-table,here is my problem i will explain it clearly.
1.I have getting the response from server,i am adding the values to layout,by using layout Layout-Inflater.
2.in our application we have streaming request.when the streaming request is turned on the values need to be updated regularly.
storing values in hash-tables
Hashtable<String, View> indicesHashtable = new Hashtable<String, View>();
For(Step 1)code i have written belowthe code.
private void addIndices(LinearLayout parent, final String key,final String value) {
LayoutInflater factory = LayoutInflater.from(mContext);
final View row = factory.inflate(R.layout.indices_values, null);
final TextView keyTextView = (TextView) row.findViewById(R.id.txtCompany);
final TextView valueTextView = (TextView) row.findViewById(R.id.txtIndex);
final Button iconImageView = (Button) row.findViewById(R.id.btnIcon);
row.setBackgroundResource(android.R.drawable.list_selector_background);
if (value.length() > 0) {
keyTextView.setText(Html.fromHtml("<b>"+indices.get(key)+"</b>"));
valueTextView.setText(Html.fromHtml(value));
if(quoteArrowIconId != -1)
iconImageView.setBackgroundResource(quoteArrowIconId);
else
iconImageView.setBackgroundDrawable(null);
}else{
keyTextView.setText(Html.fromHtml(key));
}
indicesHashtable.put(key, row);
parent.addView(row);
}
For(Step 2)i need help from you guys.
i have written code..that i have shown below.
private void handleResponseOfResponses(ResponseParser response) {
Hashtable responses = (Hashtable) response.getValue(Response_890.RESPONSES);
String[] symbols = new String[responses.size()];
int index = 0;
indicesHashtable.clear();
for(int i =indicesSymbols.length-1; i >= 0; i--){
Enumeration e = responses.keys();
while (e.hasMoreElements()) {
ResponseParser subResponse = (ResponseParser) responses.get(e.nextElement());
if (subResponse.getResponseCode() == ResponseCodes.QUOTES_RESPONSE) {
String[] quoteProperties = (String[]) subResponse.getValue(Response_312.QUOTES_KEY);
if(quoteProperties[0].equalsIgnoreCase(indicesSymbols[i])){
// symbolTable.put(quoteProperties[0].toUpperCase(), index);
symbols[index++] = quoteProperties[0];
String value = quoteValue(quoteProperties);
For displaying the values coming for response i have added (AddIndices)method
addIndices(linear_Indices, quoteProperties[0], value);
}
}
}
}
autoscroll();
indicesStreamerClient = new StreamerClient(indicesSymbols){
#Override
public void onStreamDataReceived(QuoteData quoteData) {
System.out.println("onStreamDataReceived () -> "+quoteData.getSymbol());
HERE I NEED TO ADDED ANOTHER METHOD FOR UPDATING THE VALUES..HOW I CAN WRITE THE CODE.
};
};
Streamer.getInstance(mContext).registerStramerClient(indicesStreamerClient);
}
Guys i am fresher as well as new to andriod.
Thanks in advance!!!!!!