Changing Count of ViewPager - android

How do you unlock the ability to slide to a new page after clicking a button on a previous page?
Currently I have a PagerAdapter. The code below instantiates the item. Within the getCount(), a value of 3 is returned and thus 3 slides are made. I was wondering if there was a way to only have 3 views, but after clicking a button, unlock a 4th view that you can now slide to?
#Override
public Object instantiateItem(final View collection, int position) {
final LayoutInflater inflater = (LayoutInflater) TViewPager.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
TextView tv = new TextView(TViewPager.this);
//Describe the separate layouts of views
switch (position) {
case 1:
View v1 = inflater.inflate(R.layout.expander2, null, false);
((ViewPager) collection).addView(v1, 0);
final Button button = (Button) findViewById(R.id.button_click_me);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v1) {
Toast.makeText(getBaseContext(), "+1", Toast.LENGTH_LONG).show();
//*Some code*//
}
});
return v1;
Is there a way to change the:
public int getCount() {
return 3;
}
Like a "setCount()" and then place it at the //* some code *// to increase the amount of slides?
Would adding
instantiateItem(collection,4);
work somewhere work?
Thanks,

Here's how I solved this problem. To clarify, how do you click a button and get more Pages that you can scroll into. I made:
private int NUM_VIEWS = 2;
public void setN(int N) {
this.NUM_VIEWS = N;
}
and then I changed an important line.
#Override
public int getCount() {
return NUM_VIEWS;
}
My clickListener is
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v1) {
myAdapter.setN(3);
myPager.setCurrentItem(2);
}
});
I added another case to facilitate the new item. Afterwards when I click the button, my pageadapter will expand to 3 views instead of 2 and the new case will be the new view.

getCount by default returns the number of child views of your ViewPager. By doing pager.add(layout_item) you can add a new item to the pager (of course you have to inflate it somewhere first). getCount will automatically adjust.

Related

Issues with RecyclerView only updating random cardview text size

Im trying to implement a dynamic text size option within my app. For some reason the recycler is only randomly changing text size within my cardviews instead of setting all the text to the desired size. As I scroll the list, the top cardview text will change correctly but the next 3-4 will stay default and randomly down the list another cardview text will display correctly. when i scroll back up the list, the cardview that displays correctly will change at random.
Main Activity....
// Dark Mode Menu
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
mDrawer.openDrawer(GravityCompat.START);
return true;
case R.id.menu_night_mode_day:
setNightMode(AppCompatDelegate.MODE_NIGHT_NO);
break;
case R.id.menu_night_mode_night:
setNightMode(AppCompatDelegate.MODE_NIGHT_YES);
break;
case R.id.menu_night_mode_auto:
setNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
break;
// Text Size Options
case R.id.menu_text_size_small:
setTextSize(18);
break;
case R.id.menu_text_size_medium:
setTextSize(20);
break;
case R.id.menu_text_size_large:
setTextSize(22);
break;
}
return super.onOptionsItemSelected(item);
}
// Dark Mode Menu
private void setNightMode(#AppCompatDelegate.NightMode int nightMode) {
AppCompatDelegate.setDefaultNightMode(nightMode);
if (Build.VERSION.SDK_INT >= 11) {
recreate();
}
}
// Dynamic text size
private void setTextSize(int textSize) {
TextView description = (TextView) findViewById(R.id.cardview_description);
description.setTextSize(textSize);
saveToPreferences(this, "THE_TEXT_SIZE", "" + textSize);
}
My Adapter....
public class MyPageAdapter extends Adapter<MyPageHolder> {
public List<MenuPageItems> datas;
private Activity activity;
public String dynamicTextSize;
public MyPageAdapter(Activity activity){
datas = new ArrayList<>();
this.activity = activity;
}
public void add(MenuPageItems dataModel){
datas.add(dataModel);
}
public void add(MenuPageItems dataModel, int position){
datas.add(position, dataModel);
}
public void addAll(List<MenuPageItems> menuPageItems){
datas.addAll(menuPageItems);
}
#Override
public MyPageHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(viewType, parent, false);
return createViewHolder(v, viewType);
}
#Override
public void onBindViewHolder(MyPageHolder holder, int position) {
holder.bind(datas.get(position), activity, position);
dynamicTextSize = "20";
}
#Override
public int getItemCount() {
return datas.size();
}
#Override
public int getItemViewType(int position){
return datas.get(position).getViewResId();
}
public int searchViewTypePosition(int viewType){
int i = 0;
boolean found = false;
while(i < datas.size() && !found){
if(datas.get(i).getViewResId() == viewType){
found = true;
i--;
}
i++;
}
return i;
}
public MyPageHolder createViewHolder(View v, int viewType){
return datas.get(searchViewTypePosition(viewType)).createViewHolder(v, activity, this);
}
}
Holder....
public abstract class MyPageHolder extends RecyclerView.ViewHolder{
protected final Activity activity;
protected MyPageAdapter adapter;
public TextView txtTitle, txtDescription, txtTheContent;
public ImageView imgImage;
public View view;
public MyPageHolder(View v, Activity activity, MyPageAdapter adapter) {
super(v);
this.activity = activity;
this.adapter = adapter;
imgImage = (ImageView) v.findViewById(R.id.cardview_image);
txtTitle = (TextView) v.findViewById(R.id.cardview_title);
txtDescription = (TextView) v.findViewById(R.id.cardview_description);
view = (CardView) v.findViewById(R.id.card_view);
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
/*/ this is where the magic happens when clicked /*/
}
});
}
public void bind(MenuPageItems dataModel, Activity activity, final int position) {
final MenuPageItems m = (MenuPageItems)dataModel;
imgImage.setImageResource(m.image);
txtTitle.setText(m.title);
txtDescription.setText(m.description);
//txtTheContent.setText(m.theContent);
view.setOnClickListener(new View.OnClickListener() {
#Override public void onClick(View v){
Intent cvIntent = new Intent(view.getContext(), EndpageActivity.class);
// header image to pass to endpage activity
cvIntent.putExtra("endpageHeader", m.image);
// text to pass to endpage activity
cvIntent.putExtra("endpageTitle", m.title);
cvIntent.putExtra("endpageTheContent", m.theContent);
view.getContext().startActivity(cvIntent);
}
});
}
}
Do I need to add something to my adapter or viewholder to update all the text properly?
I think I get it, but I don't see where you are setting the text size at all, you said it changes in some cards randomly.
As I see it, what needs to be done is to set the size in the Holder's bind method. This gets executed every time the card needs to be redrawn. You can read the shared preferences inside the bind(), but that is terribly inefficient since the holder's bind method will be called many times over when scrolling. You wan to avoid any excess work inside the Holders bind()
Add a dynamicTextSize member variable to the adapter and set the value with either:
Add a setText/getText size to the adapter and the activity can set this when needed.
Retrieve the text size inside the adapter's constructor and then override the notifyDataSetChanged() method and pull the value again each time that is called. Then call super.notifyDataSetChanged()
Example:
#Override
public void notifyDataSetChanged() {
this.dynamicTextSize = // Pull value from shared preferences
super.notifiyDataSetChanged();
}
What I also don't see is the dynamicTextSize value being passed into the holder. Since the holder has a reference to the adapter, you can add a getTextSize() method to the adapter, then the holder can call into the adapter to get it.
public MyPageHolder(View v, Activity activity, MyPageAdapter adapter) {
...
this.dynamicTextSize = adapter.getTextSize()
}
Finally, in the setTextSize() method you'll need to call the adapter.notifyDataSetChanged() to update the adapter.
Update 10/17
I've attempted to add some detail to by previous post.
Main Activity
// Dynamic text size
private void setTextSize(int textSize) {
// Add a call to set the text to the adapter's member variable:
mAdapter.setTextSize(textSize);
// I'm not sure what description is here... I don't see what type the member is
description.setTextSize(textSize);
saveToPreferences(this, "THE_TEXT_SIZE", "" + textSize);
}
In your adapter, add a method to set and get the text size. The set will be called by the main activity, when the text size changes, and the get is called by the holder each time it needs to set the size of the TextView.
public class MyPageAdapter extends Adapter<MyPageHolder> {
...
public String dynamicTextSize;
public void setTextSize(int textSize) {
dynamicTextSize = textSize;
}
// This will be called by the holder
public int getTextSize() {
return dynamicTextSize;
}
...
}
In your holder:
public abstract class MyPageHolder extends RecyclerView.ViewHolder{
public void bind(MenuPageItems dataModel, Activity activity, final int position) {
...
// Call into the adapter to get the text size.
int textSize = adapter.getTextSize();
txtDescription.setTextSize(textSize);
}
}
Update 10/19
I was able to get it to work with just a small change.
Add a getDynamicTextSize in your MainActivity
Add a call to the get from within the MyPageAdapter constructor.
public MyPageAdapter(Activity activity){
datas = new ArrayList<>();
this.activity = activity;
dynamicTextSize = ((MainActivity)activity).getDynamicTextSize();
}
While this does work, there is are few things it will not do for you.
Ties your fragments to always being a child of the MainActivity activity, you can get around this with an interface, but still not pretty.
Will not update the current activity as soon as the user chooses the new text size. Since the mainActivity takes the menu event, you will need to inform whatever Fragment(s) is/are active, that the text setting has changed and then call notifiyDataSetChanged on the adapter.
Does not set the size of the text outside of the custom RecyclerView. I see you have a few fragments that do not use you recycler view. These will not take the setting. The setting in the menu would make you think all the text in the app should change.
The accepted reply in this post seems to be a good way to adjust the text size for the entire app. Some changes in your app almost show that you've seen it.

onClickListener in getView() method messes up MultiChoiceModeListener()

So I have a GridView that implements the multiple choice mode listener , and every time the user taps the item it should change it's background image ; and when he/she long taps , the multi choice toolbar should appear.
However since I have on click listener in getView() it somehow blocks the other one.
(if I remove the listener from getView() , the other one works just fine)
Any advices ?
Here's my code:
MultiChoiceListener:
gView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
checkedPos = new SparseBooleanArray();
gView.setMultiChoiceModeListener(new GridView.MultiChoiceModeListener() {
#Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
currentArray = gView.getCheckedItemPositions();
int itemCount = gView.getCheckedItemCount();
switch (itemCount){
case 1:
mode.setSubtitle("One item selected.");
break;
default:
mode.setSubtitle(itemCount + " items selected.");
break;
}
...
getView():
convertView.setLongClickable(true);
final Holder finalHolder = holder;
convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(!pressed) {
finalHolder.img.setBackground(ContextCompat.getDrawable(context, R.drawable.ic_pause_bg));
pressed = true;
}
else{
finalHolder.img.setBackground(ContextCompat.getDrawable(context, R.drawable.ic_noise_bg));
pressed = false;
}
}
});
Thank you for your time!
Nevermind, I worked it out. I'm going to leave my answer if someone needs a solution for the same problem.
First of all forget about the listener in the getView() method , instead go where you have the code for your MultiChoiseModeListener and call setOnItemClickListener() for your gridView -> using the id of the image you want to change constantly:
gView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
view.setSelected(true);
ImageView image = (ImageView) view.findViewById(R.id.noise_image); //use the id given in your layout
if(!itemPressed.get(position)) {
image.setBackground(ContextCompat
.getDrawable(mContext, R.drawable.ic_running));
itemPressed.put(position,true);
}
else{
itemPressed.put(position,false);
image.setBackground(ContextCompat.getDrawable(mContext,R.drawable.ic_normal));
}
Doing so, both listeners will work.
Notice that itemPressed is a Map in order to memorize
which item was clicked so when changing background images , there is
no confusion.

A TextView change applies to multiple TextViews using ListView and ArrayAdapter

I've started working on a small project not to long ago, the main goal is to forge a way for me to keep track of my actions during the course of 100 weeks.
I'm still a rookie android developer and I've encountered an issue that I couldn't explain.
Basically I've populated a ListView using the ArrayAdapter with a list containing 100 strings (Week1, Week2, Week3 ... Week100)
Setting up an onclicklistener on each of the TextViews so that when a user performs a click on a textview, the background color would change to red.
However; whenever I click a single textview - more than a single textview is being colored.
Notes:
I'm using a ScrollView to scroll through the entire list. (Once populated, the 100 week list fills up the entire screen, the scroll view is used to access the entire list.)
I also saved a reference to the currently painted textview so I could make sure that when a user clicks a different textview, the previous one would lose its red background.
MainActivity initialization:
public class MainActivity extends ActionBarActivity
{
TextView selectedWeek; // Reference to the selected week.
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
populateWeekList(); // Populating the ListView
initWeekClick(); // Initializing click listener
}
Populating the ListView:
public void populateWeekList()
{
String[] weeks = new String [100]; // 100 weeks
for (int i=0; i<100;i++)
{
weeks[i] = "Week"+(i+1);
}
ArrayAdapter<String> weekAdapter = new ArrayAdapter<String>(
this,
R.layout.weeksview,
weeks
);
// R.id.weekTypeList is just a normal TextView.
ListView weekList=(ListView) findViewById(R.id.weekTypeList);
weekList.setAdapter(weekAdapter);
}
Code for initializing onClickListener and saving the selectedWeek reference:
public void initWeekClick()
{
ListView weekList=(ListView) findViewById(R.id.weekTypeList);
weekList.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> parent, View viewClicked, int position, long id)
{
if (selectedWeek != null)
{
selectedWeek.setBackgroundColor(0);
}
TextView clicked = (TextView) viewClicked;
// Change clicked TextView color to red.
clicked.setBackgroundColor(getResources().getColor(android.R.color.holo_red_light));
// Save the selected week reference
selectedWeek = clicked;
}
});
}
Ok, your background is shuffling because when you scroll your ListView getView() is called and it consider your current position of TextView(as current view) and set background on it as it detect setBackground() method at onClick listener on it..
First I recommend to create a Adapter class extends ArrayAdapter<?>
Solution 1 :
Use setTag() at onClick listener on your text view like..
text.setTag(position);
and above it use getTag() and put condition
if(holder.text.getTag().equals(position)){
holder.text.setBackgroundColor(Color.BLUE);
}else{
holder.text.setBackgroundColor(Color.WHITE);
}
Solution 2 :
Added this to onCreate method
ArrayList<String> _array = new ArrayList<String>();
for(int i=0 ; i <1000; i ++){ // 1000 value
_array.add(i+"");
}
list.setAdapter(new MainAdapter(this, _array)); // pass you list here
ArrayAdapter class :
public class MainAdapter extends ArrayAdapter<String> {
ArrayList<String> _st = new ArrayList<String>();
ArrayList<Integer> check = new ArrayList<Integer>();
Context _context;
public MainAdapter(Context context,ArrayList<String> _st) {
super(context,R.layout.main, _st); // your inflate layout
this._context = context;
this._st = _st;
}
#Override
public int getCount() {
return _st.size();
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
//---//
// check if current position is there in arraylist
if(checking(position)){
holder.text.setBackgroundColor(Color.BLUE);
}else{
holder.text.setBackgroundColor(Color.WHITE);
}
holder.text.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// set background and put value in array list
holder.text.setBackgroundColor(Color.BLUE);
check.add(position);
}
});
return convertView;
}
// this will check whether current position is there is array list or not and if it there it will break loop and return true
public boolean checking(int position){
boolean fine = false;
for(int i=0; i<check.size();i++){
if(position == check.get(i)){
fine = true;
break;
}
}
return fine;
}
}
public class ViewHolder{
TextView text;
}
}
I don't how much I am ethical in this code...but as you have specified that you have 100 value.I have tested it on 1000 value and it worked
I am not expert so let me know if I am wrong somewhere
Hope it works !!!

Loading order of viewpager in android

Imagine there is a viewpager with 4 page, the 1st and 2nd page are storing the edittext, and the third one need to display the inputed data from 1st and 2nd page.
The problem is , viewpager pre-load the pervious page and next page , if I create the custom adapter like that:
Custom adapter
#Override
public Object instantiateItem(ViewGroup container, int position) {
rootView = (LinearLayout) LayoutInflater.from(ctx).inflate(pages[position], null);
if (position == 0) {
form1(rootView);
} else {
form2(rootView);
}
((ViewPager)container).addView(rootView);
return rootView;
}
Example function form2
private void form2(View rootView){
TextView previous_page = (TextView) rootView.findViewById(R.id.previous_page);
TextView next_page = (TextView) rootView.findViewById(R.id.next_page);
final EditText type = (EditText) rootView.findViewById(R.id.edit_type);
final EditText amount = (EditText) rootView.findViewById(R.id.edit_amount);
final Spinner period = (Spinner) rootView.findViewById(R.id.edit_period);
final EditText name = (EditText) rootView.findViewById(R.id.edit_name);
final EditText phone_no = (EditText) rootView.findViewById(R.id.edit_phone_no);
final EditText email = (EditText) rootView.findViewById(R.id.edit_email);
previous_page.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
viewPager.setCurrentItem(0, true);
top_bar.setImageResource(R.drawable.form_1_header);
}
});
next_page.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String[] input_list = {amount.getText().toString(),name.getText().toString(),phone_no.getText().toString(),email.getText().toString()};
String invalid_msg = check_valid(input_list);
if (invalid_msg.equals("")) {
new FormHandler(ctx,formListener).execute(type.getText().toString(),amount.getText().toString(),period.getSelectedItem().toString(),name.getText().toString(),phone_no.getText().toString(),email.getText().toString());
} else {
Toast.makeText(ctx, invalid_msg ,Toast.LENGTH_LONG).show();
}
}
});
}
Then , for example if I enter the 1st page, it call the instantiateItem 2 times, the position are 0 and 1 , and it called the form1() and the form2(), which I expect only when I enter that page , it call the function of that page . e.g. At 1st page , run form1(), At 2nd page , run form2(). How to fix that? thanks.
Update (1):
It caused a problem, when I enter 2nd tab , it preload the 3rd tab, which call the form3(), so after I input the data in those edittext at 2nd tab, and go to the 3rd tab, it does not call form3() again, so the 3rd tab does not display enter data from 2nd tab (The view was preload and instantiate already)
Update (2):
The page is not a fragment , it is a layout and inflate at the adapter(named "rootview" and the pages array is:)
int[] pages = {R.layout.form_1,R.layout.form_2,R.layout.form_3,R.layout.form_4};
Update (3):
My whole viewpager
private class ViewPageAdapter extends PagerAdapter {
// Declare Variables
public int[] pages;
private LinearLayout rootView;
public ViewPageAdapter(int[] _pages) {
pages = _pages;
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == (LinearLayout) object;
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
rootView = (LinearLayout) LayoutInflater.from(ctx).inflate(
pages[position], null);
if (position == 0) {
form1(rootView);
} else if (position == 1) {
form2(rootView);
} else if (position == 2) {
form3(rootView);
} else if (position == 3) {
form4(rootView);
}
((ViewPager) container).addView(rootView);
return rootView;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((LinearLayout) object);
}
#Override
public int getCount() {
return pages.length;
}
}
You can override the setPrimaryItem method in adapter. this method will give the current displaying object. This may help you.
#Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
if (mobject != object) {
mObject=objet; //mObject is global variable in adapter
//You can update your based on your logic like below
View view == (LinearLayout) object;
form4(view);
}
super.setPrimaryItem(container, position, object);
}
Then , for example if I enter the 1st page, it call the instantiateItem 2 times, the position are 0 and 1 , and it called the form1() and the form2(), which I expect only when I enter that page , it call the function of that page . e.g. At 1st page , run form1(), At 2nd page , run form2(). How to fix that? thanks.
you can not fix that, because of giving better UX to user setOffscreenPageLimit(0); dose not work and the default value is always 1 which means it always preloads your next and previous page.
so after I input the data in those edittext at 2nd tab, and go to the
3rd tab, it does not call form3() again, so the 3rd tab does not
display enter data from 2nd tab (The view was preload and instantiate
already)
you can save your data in SharedPreferaces and read them in onResume method of tab3. in this way you will get correct data from tab2 and tab1.

android: buttons created using button adapter is not in the right order

new to android. I created 12 (3 rows, 4 columns) buttons in a GridView and I created a toast to display something after a button is pressed by following a tutorial. The buttons are displaying on the screen correctly, but the toast messages are not. When I press top left button, I get the bottom left toast. When I press middle left button, I get middle right toast. When I press bottom left button, I get top right toast.
Visually:
button location:
1 2 3 4
5 6 7 8
9 10 11 12
toast message
9 10 11 12
8 7 6 5
4 3 2 1
Here's the adapter code:
public class KeypadAdapter extends BaseAdapter {
private Context mContext;
// Declare button click listener variable
private OnClickListener mOnButtonClick;
// Method to set button click listener variable
public void setOnButtonClickListener(OnClickListener listener) {
mOnButtonClick = listener;
}
public KeypadAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mButtons.length;
}
public Object getItem(int position) {
return mButtons[position];
}
public long getItemId(int position) {
return 0;
}
private KeypadButtons[] mButtons = { KeypadButtons.ADD,
KeypadButtons.SUBTRACT, KeypadButtons.MULTIPLY,
KeypadButtons.DIVIDE, KeypadButtons.DET, KeypadButtons.INV,
KeypadButtons.POW2, KeypadButtons.POWN, KeypadButtons.TRANSPOSE,
KeypadButtons.NORM1, KeypadButtons.NORM2, KeypadButtons.NORMINF };
#Override
public View getView(int position, View convertView, ViewGroup parent) {
Button btn;
if (convertView == null) { // if it's not recycled, initialize some
// attributes
btn = new Button(mContext);
KeypadButtons keypadButton = mButtons[position];
if (keypadButton != KeypadButtons.DUMMY) {
btn.setOnClickListener(mOnButtonClick);
}
// Set CalculatorButton enumeration as tag of the button so that we
// will use this information from our main view to identify what to
// do
btn.setTag(keypadButton);
} else {
btn = (Button) convertView;
}
btn.setText(mButtons[position].getText());
return btn;
}
}
and here's the the activity code
public class MainActivity extends Activity {
GridView mKeypadGrid;
KeypadAdapter mKeypadAdapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get reference to the keypad button GridView
mKeypadGrid = (GridView) findViewById(R.id.gridView);
// Create Keypad Adapter
mKeypadAdapter = new KeypadAdapter(this);
// Set adapter of the keypad grid
mKeypadGrid.setAdapter(mKeypadAdapter);
// Set button click listener of the keypad adapter
mKeypadAdapter.setOnButtonClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Button btn = (Button) v;
// Get the KeypadButton value which is used to identify the
// keypad button from the Button's tag
KeypadButtons keypadButton = (KeypadButtons) btn.getTag();
// Process keypad button
ProcessKeypadInput(keypadButton);
}
});
mKeypadGrid.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
}
});
}
protected void ProcessKeypadInput(KeypadButtons keypadButton) {
// TODO Auto-generated method stub
Toast.makeText(
MainActivity.this,
keypadButton.getText().toString() + " "
+ keypadButton.toString(), Toast.LENGTH_SHORT).show();
}
}
At first it seems the order of the toasts are reversed. So I tried doing
KeypadButtons keypadButton = mButtons[mButtons.length - 1 - position];
That fixed the bottom two rows but he top row is still reversed.
Thanks in advance.
Views are recycled (as you obviously know because you're checking if the convertview is null). A simple fix here is to move the btn.setTag(keypadButton); to outside of theif(convertView==null)` block and execute it always before you return from getView();

Categories

Resources