Clear cache listview android [closed] - android

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Ara>Button,Dizi>array.
when i clicked button list the botton of list view? is there any body help me?
Help,help
ps: i tried something but not worked
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);//
setContentView(R.layout.activity_main);
Ara = (Button)findViewById(R.id.btnAra);
multitv =(MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
adapter =new ArrayAdapter<String>(this,android.R.layout.select_dialog_singlechoice, Neresi());
multitv.setAdapter(adapter);
multitv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
Aranan = (String)multitv.getText().toString();
listView = (ListView) findViewById(R.id.list);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
Ara.setOnClickListener(this) ;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId() == R.id.btnAra)
{
String []dizi =null;
dizi = Belirtiler("Baş");
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice,dizi);
listView.setAdapter(adapter);
}
}

for refreshing list see the following link
How to refresh Android listview
Android Updating ListView
Android: how to refresh ListView contents

Related

What to use instead of RecyclerView if not recycling items [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am a beginner and I have seen many tutorials on how to create a list using RecyclerView, but I can't find any how to use a list without recycling. I have a list of 3 items. what type of view should I use if I don't want to recycle?
Another way to look at you list would be as simple items (since there are only 3). You can just add items to a LinearLayout with orientation as vertical.
You can even go further and create a common item layout XML, and using a for loop, inflate your LinearLayout. Example:
//create item class
#AllArgsConstructor #Getter
private static class Item {
private int iconId;
private String mainText;
private String detailsText;
}
// create item
private Item ITEM_1 = new Item(R.drawable.some_drawable, getString(R.string.some_string), getString(R.string.some_string));
//add item to an arrayList (only add what you want that logged in user to see :D)
itemList.add((ITEM_1))
//layout you want to add to
#BindView(R.id.content) LinearLayout layoutToAddTo;
LayoutInflater inflater = LayoutInflater.from(getContext());
for (Item item : itemList) { // a list which holds all your Items
//XML that the Item class matches.
View card = inflater.inflate(R.layout.card, layoutToAddTo, false);
bindContent(card, item);
card.setOnClickListener(__ -> /* set your listener */));
layoutToAddTo.addView(card);
}
//bind your content
private void bindContent(View view, Item item) {
((ImageView) view.findViewById(R.id.card_icon)).setImageDrawable(ContextCompat.getDrawable(context, item.getIconId());
((TextView) view.findViewById(R.id.card_main_text)).setText(item.getMainText());
((TextView) view.findViewById(R.id.card_details_text)).setText(item.getDetailsText());
}
Best for few items, otherwise try to use Recycler View.
You can use ListView if you don't want to recycle the list item.
Here ListView

listview setonitemclicklistener with arrayadapter [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
When try tu add method setOnItemClikListener show me this error: setOnItemClikListener (ItemClikListener) in AdapterView cannot be applied to ().
My code is:
List<String> weekForecast = new ArrayList<String>(Arrays.asList(forecastArray));
mForecastAdapter = new ArrayAdapter<String>(getActivity(),R.layout.list_item_forecast,R.id.list_item_forecast_textview,weekForecast);
ListView listViewForecast = (ListView) rootView.findViewById(R.id.listview_forecast);
listViewForecast.setAdapter(mForecastAdapter);
listViewForecast.setOnItemClickListener();
Try the following :
List<String> weekForecast = new ArrayList<String>(Arrays.asList(forecastArray));
mForecastAdapter = new ArrayAdapter<String>
(getActivity(),android.R.layout.simple_list_item1,weekForecast);
ListView listViewForecast = (ListView) rootView.findViewById(R.id.listview_forecast);
listViewForecast.setAdapter(mForecastAdapter);
listViewForecast.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//Do your thing here
}
});

Android to display a text on Text View from String-array items and changing it on left and right swipe

I am just days old to android.In my application I have a List View displaying planets name, and when user clicks on the list view item i.e any of the planet name, another activity will gets opened in respect of which planet is clicked on list view, like suppose if user choose "earth", an activity gets opened having Text View display and on that text view, I am displaying some facts(say 10 facts) about planet Earth that I have stored in string-array items(displaying only 1 fact at a time). Now, when user swipes left or right,the text gets changed depending on whether it is swiped left or right.
Tasks that I've managed to perform
I am able to set the list view items i.e lists of planet and I've implemented the onItemSelectListener() to it.
I've created the 9 activities also for each planet and I am able to call the particular activity for which the item is clicked using Intent().
I have declared the facts for each planet in string-array items.But don't know how to set them on Text View.
Tasks that I'm trying to achieve
Like when click on Earth, I am starting another activity that is displaying the first fact from the string-array items. I want when user swipes left or right, the second fact will gets displayed.
P.S.. Though I am able to change the facts from string-array items, but for that I was using next and previous buttons in which I using a counter, but I want to use the swipe.
I tried several tuts about swipes but did understand much. Please help and suggest.
One more thing, I am having a Samsung Galaxy Y S5360, how to install plug-ins in it, so that I can test my application directly because my emulator sucks.(i've heard using Kies slows down the system-any other alternative you can offer)
Thanks a lot
MainActivity.java
public class MainActivity extends Activity {
ListView lv;
String[] list = new String[] { "Mercury","Venus","Earth","Mars","Jupiter",
"Saturn","Uranus","Neptune","Pluto" };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView) findViewById(R.id.lv);
ArrayAdapter<String> adps = new ArrayAdapter<String>(
getApplicationContext(), android.R.layout.simple_list_item_1,
list);
lv.setAdapter(adps);
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
long arg3) {
// TODO Auto-generated method stub
switch (pos) {
case 0:
Intent intent = new Intent(MainActivity.this,
Mercury.class);
startActivity(intent);
break;
// similarly for all other 8 cases
default:
break;
}
}
});
// final String[] quo = getResources().getStringArray(R.array.quotes);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Mercury.java
public class motivatinal extends Activity {
int counter = 0;
TextView mercury;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.motivational);
String[] mer = getResources().getStringArray(R.array.motivational);
mercury.setText(mer);
// do not know how to display string array items on text view.
// mercury.settext is showing error.
}
}

Adapter_Android listview [duplicate]

This question already has an answer here:
Setting more than one adapter for a single list view
(1 answer)
Closed 8 years ago.
My problem is that I have two classes and I want to show them in a ListView. I want to merge between those ones into one list view in AsyncTask, there is my code and I need a help.
protected Void doInBackground(Void... params) {
twitt = Services.getTwitterTv();
twittns = Services.getTwitter();
return null;
}
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
for (Twitter twitts : twitt)
for(Twitter twittn: twittns)
{
System.out.println(twitts.getTexte());
System.out.println(twittn.getTexte());
}
progressDialog.dismiss();
twitt.addAll(Services.getTwitter());
twitt.addAll(Services.getTwitterTv());
TwitterAdapter adapter = new TwitterAdapter(TwitterTv.this, R.layout.twitts_item, twitt );
TwitterAdapter adapter2 = new TwitterAdapter(TwitterTv.this, R.layout.twitts_item, twittns );
twitterlist.setAdapter(adapter);
twitterlist.setAdapter(adapter2);
}
}
So marge the date and in your addapter ask what data is it. If its data1 then infalte view number one, if it's data2 then inflate view number2.
Then just populate the view with the data and you are done.

add item in array list of android [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I want to add value getting from text view of android to an existing array list.e.g. my current array list contain values Cricket,Football and by text view I want to add hockey in array list at last position ..then my array list become Cricket ,football,hockey. My array list of cricket and football is coming from previous activity.
But now it add only cricket and football but does not add hockey
How can I do it?
resultArrGame+=resultArrGame.add(txtGame.getText().toString());
This will definitely work for you...
ArrayList<String> list = new ArrayList<String>();
list.add(textview.getText().toString());
list.add("B");
list.add("C");
You're trying to assign the result of the add operation to resultArrGame, and add can either return true or false, depending on if the operation was successful or not. What you want is probably just:
resultArrGame.add(txt.Game.getText().toString());
you can use this add string to list on a button click
final String a[]={"hello","world"};
final ArrayAdapter<String> at=new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1,a);
final ListView sp=(ListView)findViewById(R.id.listView1);
sp.setAdapter(at);
final EditText et=(EditText)findViewById(R.id.editText1);
Button b=(Button)findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
// TODO Auto-generated method stub
int k=sp.getCount();
String a1[]=new String[k+1];
for(int i=0;i<k;i++)
a1[i]=sp.getItemAtPosition(i).toString();
a1[k]=et.getText().toString();
ArrayAdapter<String> ats=new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1,a1);
sp.setAdapter(ats);
}
});
So on a button click it will get string from edittext and store in listitem.
you can change this to your needs.
item=sp.getItemAtPosition(i).toString();
list.add(item);
adapter.notifyDataSetChanged () ;
look up ArrayAdapter.notifyDataSetChanged()

Categories

Resources