logo
down
shadow

Correct way to add more views to adapter


Correct way to add more views to adapter

By : Brandon
Date : November 19 2020, 03:01 PM
should help you out The problem may be that when you bind your post views, you get data with the given position.
You should decrement index to not jump position in your data array corresponding to your ad views on every six items.
code :
case Posts_View:
        posts_handler_b Normal_Holder = (posts_handler_b) holder;

        retrieve_data model = mPosts_List.get(position - (position / 6) - 1);
        Normal_Holder.Card_View_Time(model.getH());
        Normal_Holder.Card_View_Handler(model.getK(),position);break;


Share : facebook icon twitter icon
More than one views (inflaters) in one Adapter

More than one views (inflaters) in one Adapter


By : user3431986
Date : March 29 2020, 07:55 AM
it helps some times You need to implement getViewTypeCount() and getItemViewType() to teach the AdapterView about your multiple types of rows.
For example, here is an activity with a ListAdapter that has separate layouts for headers and details:
code :
/***
  Copyright (c) 2008-2012 CommonsWare, LLC
  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  use this file except in compliance with the License. You may obtain   a copy
  of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
  by applicable law or agreed to in writing, software distributed under the
  License is distributed on an "AS IS" BASIS,   WITHOUT WARRANTIES OR CONDITIONS
  OF ANY KIND, either express or implied. See the License for the specific
  language governing permissions and limitations under the License.

  From _The Busy Coder's Guide to Android Development_
    http://commonsware.com/Android
 */

package com.commonsware.android.headerdetail;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class HeaderDetailListDemo extends ListActivity {
  private static final String[][] items= {
      { "lorem", "ipsum", "dolor", "sit", "amet" },
      { "consectetuer", "adipiscing", "elit", "morbi", "vel" },
      { "ligula", "vitae", "arcu", "aliquet", "mollis" },
      { "etiam", "vel", "erat", "placerat", "ante" },
      { "porttitor", "sodales", "pellentesque", "augue", "purus" } };

  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setListAdapter(new IconicAdapter());
  }

  class IconicAdapter extends BaseAdapter {
    @Override
    public int getCount() {
      int count=0;

      for (String[] batch : items) {
        count+=1 + batch.length;
      }

      return(count);
    }

    @Override
    public Object getItem(int position) {
      int offset=position;
      int batchIndex=0;

      for (String[] batch : items) {
        if (offset == 0) {
          return(Integer.valueOf(batchIndex));
        }

        offset--;

        if (offset < batch.length) {
          return(batch[offset]);
        }

        offset-=batch.length;
        batchIndex++;
      }

      throw new IllegalArgumentException("Invalid position: "
          + String.valueOf(position));
    }

    @Override
    public long getItemId(int position) {
      return(position);
    }

    @Override
    public int getViewTypeCount() {
      return(2);
    }

    @Override
    public int getItemViewType(int position) {
      if (getItem(position) instanceof Integer) {
        return(0);
      }

      return(1);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      if (getItemViewType(position) == 0) {
        return(getHeaderView(position, convertView, parent));
      }

      View row=convertView;

      if (row == null) {
        row=getLayoutInflater().inflate(R.layout.row, parent, false);
      }

      ViewHolder holder=(ViewHolder)row.getTag();

      if (holder == null) {
        holder=new ViewHolder(row);
        row.setTag(holder);
      }

      String word=(String)getItem(position);

      if (word.length() > 4) {
        holder.icon.setImageResource(R.drawable.delete);
      }
      else {
        holder.icon.setImageResource(R.drawable.ok);
      }

      holder.label.setText(word);
      holder.size.setText(String.format(getString(R.string.size_template),
                                        word.length()));

      return(row);
    }

    private View getHeaderView(int position, View convertView,
                               ViewGroup parent) {
      View row=convertView;

      if (row == null) {
        row=getLayoutInflater().inflate(R.layout.header, parent, false);
      }

      Integer batchIndex=(Integer)getItem(position);
      TextView label=(TextView)row.findViewById(R.id.label);

      label.setText(String.format(getString(R.string.batch),
                                  1 + batchIndex.intValue()));

      return(row);
    }
  }
}
Different views in custom adapter in android

Different views in custom adapter in android


By : Eslam Abd El Rahman
Date : March 29 2020, 07:55 AM
around this issue I'm new in android.. I would like to create the different views in Listview using Custom Adapter. Please suggest me how I can do this. , Define a custom layout of how you want the list row like this
code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="@dimen/headerHeightCustRow"
 android:background="#FFFFFF"
 tools:ignore="HardcodedText" >

<TextView
    android:id="@+id/txtName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="2dip"
    android:layout_marginLeft="@dimen/viewSpace1"
    android:text="Varun Mad"
    android:textSize="@dimen/logout_textSize"
    android:textStyle="bold"
    android:textColor="@color/orange_normal" />

<TextView
    android:id="@+id/txtCustId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_marginLeft="@dimen/viewSpace3"
    android:layout_marginTop="@dimen/viewSpace3"
    android:layout_marginRight="@dimen/viewSpace3"
    android:text="10549"
    android:layout_centerVertical="true"
    android:textColor="@color/orange_normal"
    android:textSize="15sp" />

<TextView
    android:id="@+id/txtPhone"
    android:layout_below="@id/txtName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/viewSpace1"
    android:text="(886)677-8855"
    android:textColor="@color/orange_normal"
    android:textSize="@dimen/vsText" />

<TextView
    android:id="@+id/txtEmail"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/viewSpace1"
    android:text="ggg@gmail.com"
    android:textSize="@dimen/vsText"
    android:layout_below="@id/txtPhone"
    android:textColor="@color/orange_normal" />

<View
    android:layout_width="fill_parent"
    android:layout_height="0.5dip"
    android:layout_alignParentBottom="true"
    android:background="@color/greyDark" />
public class SearchCustomerAdapter extends BaseAdapter {
Context ctx;
LayoutInflater lInflater;
ArrayList<SearchCustomerItem> objects;

public SearchCustomerAdapter(Context context, ArrayList<SearchCustomerItem> products) {
    ctx = context;
    objects = products;
    lInflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount() {
    return objects.size();
}

@Override
public Object getItem(int position) {
    return objects.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
    if (view == null) {
        view = lInflater.inflate(R.layout.search_cust_row, parent, false);
    }

    SearchCustomerItem p = getProduct(position);

    ((TextView) view.findViewById(R.id.txtName)).setText(p.customerName);

    if (p.customerEmail.compareTo("anyType{}") == 0) {
        ((TextView) view.findViewById(R.id.txtEmail)).setText("");
    } else {
        ((TextView) view.findViewById(R.id.txtEmail)).setText(p.customerEmail);
    }
    ((TextView) view.findViewById(R.id.txtPhone)).setText(p.customerPhone);
    ((TextView) view.findViewById(R.id.txtCustId)).setText(p.customerId);

    return view;
}

SearchCustomerItem getProduct(int position) {
    return ((SearchCustomerItem) getItem(position));
}

@SuppressWarnings("unused")
ArrayList<SearchCustomerItem> getBox() {
    ArrayList<SearchCustomerItem> box = new ArrayList<SearchCustomerItem>();
    for (SearchCustomerItem p : objects) {
      //  if (p.box)
      //      box.add(p);
    }
    return box;
}    
public class SearchCustomerItem {

public String customerName;
public String customerPhone;
public String customerEmail;
public String customerId;

 public SearchCustomerItem(String _cName, String _cPhone, String _cEmail, String _cCustId) {
     customerName = _cName;
     customerPhone = _cPhone;
     customerEmail = _cEmail;
     customerId = _cCustId;
 }  
}
SearchCustomerAdapter boxAdapter;
ArrayList<SearchCustomerItem> products = new ArrayList<SearchCustomerItem>();
products.add(new SearchCustomerItem("CustomerName","PhoneNo","Cust_EmailId","Cust_Id"));
boxAdapter = new SearchCustomerAdapter(SearchActivity.this, products);
list.setAdapter(boxAdapter);        
Correct structure for a Django application and handling the views and sub views

Correct structure for a Django application and handling the views and sub views


By : Ladybug
Date : March 29 2020, 07:55 AM
I wish did fix the issue. The problem is simply that you haven't terminated your dashboard URL pattern, so it matches both URLs. It should be:
code :
url(r'^dashboard$', views.dashboard, name='dashboard'),
how can i use views from my method in custom adapter?

how can i use views from my method in custom adapter?


By : user1905263
Date : March 29 2020, 07:55 AM
help you fix your problem You need to implement and set a listener interface for your viewholders to be able to communicate with them through your activity:
Your custom adapter:
code :
     private OnItemClickListener onItemClickListener; //ADD THIS GLOBAL FIELD

     //ADD THIS SETTER
     public void setOnItemClickListener(OnItemClickListener onItemClickListener) 
     {
         this.onItemClickListener = onItemClickListener;
     }

     @Override
     public void onBindViewHolder(final DeMontageListAdapter.MyViewHolder holder, 
     final int position) {

     holder.txt_piston_code.setText(list.get(position).getPistonCode());

     // SET YOUR LISTENER TO EACH OF YOUR ITEM VIEWS
     holder.txt_piston_code.setOnClickListener(v ->
            onItemClickListener.onClickItem(position);
     }

     // ADD THIS INTERFACE AT THE END
     interface OnItemClickListener {
        void onClickItem(int position);
     }
    public class MyActivity implements DemontageListAdapter.OnItemClickListener {

        DemontageListAdapter adapter;

        { ... }

        adapter = new DemontageListAdapter (...)
        adapter.setOnItemClickListener(this); // ADD THIS BEFORE YOU SET YOUR ADAPTER TO YOUR ACTIVITY
        recyclerView.setAdapter(adapter);

        //OVERRIDE THIS METHOD OF YOUR INTERFACE
        @Override
        public void onClickItem(int position) {
            adapter.changeTextViewBackground(position);
        }
    }
What adapter to use for ExpandableListView with non-TextView views?

What adapter to use for ExpandableListView with non-TextView views?


By : user3861542
Date : November 20 2020, 07:00 PM
help you fix your problem I have an ExpandableListView in which I'd like to have controls other than TextView. Apparently, SimpleExandableListViewAdapter assumes all the controls are TextViews. A cast exception is generated if they are not. , Here is some code that I actually just wrote for one of my apps:
Related Posts Related Posts :
  • How to set epoch in Firestore using server time
  • Android 8 Geofences on killed app
  • When I Try to Change the Color of SnackBar TextView App Crashes
  • cannot access outer class variable for datasnapshot.haschild() method
  • Cannot read image written to file
  • Databinding seems to be broken after adding Room
  • switch statement Error : Statement must be prepended with case label
  • View local firebase database with Stheto on Android
  • How to employ keyed-hash message authentication code (HMAC) with Android Keystore
  • Prevent inviting existing users or previously invited
  • How to overwrite windowSoftInputMode using edit-config tag in cordova
  • Difference between Loader and AsyncTask
  • In Firebase Android, retrieve the value of a child node and save it in a boolean variable
  • when i scroll the custom list in my android app then the favorite icon which is part of the custom adapter changes on it
  • adding room dependency gives manifest merge error
  • Visibility of RelativeLayout change on scrolling Gridview
  • Strange LiveData behavior vs ObservableField
  • Which layout is used for clash of clans home screen? We can scroll it horizontal as well as vertical. Please illuminate
  • RxJava: Know when observable is finished and return Boolean Observable to the caller
  • how to use savedInstanceState to save camera information when the orientation change occure
  • Style React-Native via Styles.xml
  • Keyboard won't show after calling InputMethodManager.showSoftInput
  • Compiling ffmpeg for Android on OSX
  • Button does not get clicked on the first attempt
  • AR Core performance, learning curve and comparison with other frameworks
  • Codename one : Attaching images to email message fails
  • Error: Unsupported type 'viewItem' in Android build
  • setLayoutParams on ConstraintLayout does not change size
  • How to profile the fetch time of the android gradle libraries
  • Kotlin setOnclickListener
  • Naming convention for methods returning RxJava's Completable
  • Conv3D not working
  • FFmpeg audio video merge command
  • Do you have to use gradle-experimental for JNI?
  • How to get key hashes for facebook for facebook app?
  • ZXing not calling onActivityResult, When scanning QR Code
  • Integration of Android Native module with existing Xamarin Native Project
  • Restore RecyclerView state after rotating
  • ViewModelProviders java.lang.RuntimeException trying to instantiate class which inherit AndroidViewModel
  • SKD19 vs SDK24 - Usage of API documented as @since 1.8+
  • filter option in list view fragment activity
  • Picture from camera not showing up in second activity
  • How to change imageview according to screen size
  • How to copy Android Studio project to remote Git (NOT GitHub) server
  • How to get React-Native to announce specific accessibility message via AccessibiliyManager?
  • Change colors of com.tech.freak.wizardpager.ui.StepPagerStrip
  • Android fullscreen activity shows ActionBar
  • Turn on the screen when timer calls onFinish()
  • Would like a bit of clarification with SQLite database's onUpgrade method
  • Use ObjectBox with Libgdx
  • How to make combine Gregorian and Hijri calendar in Android?
  • Try to read text file from sdcard in other language
  • "App not installed" message when installed apk
  • How to execute a designated test suite class in Firebase Test Lab
  • play music with background service
  • background not visible on LG G3
  • should every View have an id?
  • Realm object server sync on low connection.
  • Getting error in android support library
  • Instant app zip uploading error
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org