Question

I had posted a question in here yesterday. Since I did not add proper code snippets, I hardly got solution. So here I am, posting it all new. Just to keep active on the questions.

I have three tabs- A, B, C. Each of these tabs is an ActivityGroup class. TabC contains a listView. TabA and TabB has buttons to go to TabC.

XML file of a class in tabC (This is for request coming from Tab A)

<LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

       <ListView
        android:id="@+id/enquiryListViewA"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="7dp" >
</LinearLayout>

the target class in tabC is

public class TestClass extends Activity {
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         if(0 == Constants.requestID) { //requestID is used to identify the tab
             //request from tab A
             setContentView(R.layout.custom_fullpicture_A);
         } else { //request from tab B
             setContentView(R.layout.custom_fullpicture_B);
         }
}

And in the Handler class, I am setting adapter. Here also I check the valid listView depending on the tab type

 if(0 == Constants.requestID) {
   ListView enquiryView = (ListView) ((Activity) childContext).findViewById(R.id.enquiryListViewA);
   adapterA = new CustomFullPictureAdapter(childContext, msg.obj);
   enquiryView.setAdapter(adapterA);
 } else {
   ListView enquiryView = (ListView) ((Activity) childContext).findViewById(R.id.enquiryListViewB);
   adapterB = new CustomFullPictureAdapter(childContext, msg.obj);
   enquiryView.setAdapter(adapterB);
 } 

And the getView method of adpater class is

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    System.out.println("Full Picture adapter: CONVERT VIEW : :: " + convertView);
    System.out.println("Data count from DB :: " + getCount());
    int viewType = Constants.requestID;

    View viewAccounts = null;
    View viewCM = null;
    View view = null;
    View masterView = null;

    if(viewType == 0) {
        viewAccounts = convertView;
    } else if(viewType == 1) {
        viewCM = convertView;
    } else {
        view = convertView;
    }


    if(viewAccounts == null) {
        holder = new ViewHolder();
         if(!Constants.isLoggedInCustomer) { //logged in as user
             viewAccounts = mInflater.inflate(R.layout.custom_fullpicturerow_A, null);

            holder.salesCostAcc = (TextView) viewAccounts.findViewById(R.id.vSalesCostAcc);
            holder.profitAcc = (TextView) viewAccounts.findViewById(R.id.vProfitAcc);
             holder.gpAcc = (TextView) viewAccounts.findViewById(R.id.vGpAcc);
             holder.salesValueAcc = (TextView) viewAccounts.findViewById(R.id.vSalesValueAcc);
             holder.quantityAcc = (TextView) viewAccounts.findViewById(R.id.vQuantityAcc);
             holder.transactionCountAcc = (TextView) viewAccounts.findViewById(R.id.vTransAcc);
             holder.avgPriceAcc = (TextView) viewAccounts.findViewById(R.id.vAvgPriceAcc);
             holder.objectNameAcc = (TextView) viewAccounts.findViewById(R.id.vObjectNameAcc);
             holder.objectCodeAcc = (TextView) viewAccounts.findViewById(R.id.vObjectCodeAcc);

             holder.salesValueAcc.setText(searchArrayList.get(position).getSalesValue());
             holder.quantityAcc.setText(searchArrayList.get(position).getQuantity());
             holder.transactionCountAcc.setText(searchArrayList.get(position).getTransactionCount());
             holder.avgPriceAcc.setText(searchArrayList.get(position).getAvgPrice());     
             holder.objectNameAcc.setText(searchArrayList.get(position).getObjectName());
             holder.objectCodeAcc.setText(searchArrayList.get(position).getObjectCode());

             holder.salesCostAcc.setText(searchArrayList.get(position).getSalesCost());
            holder.profitAcc.setText(searchArrayList.get(position).getProfit());
             holder.gpAcc.setText(searchArrayList.get(position).getProfitMargin());

             masterView = viewAccounts;

             viewAccounts.setTag(holder);
         } else {

         }
    } 



    if(view == null) {
        holder = new ViewHolder();
         if(!Constants.isLoggedInCustomer) { //logged in as user
             viewCM = mInflater.inflate(R.layout.custom_fullpicturerow_B, null);

            holder.salesCost = (TextView) viewCM.findViewById(R.id.vSalesCost);
            holder.profit = (TextView) viewCM.findViewById(R.id.vProfit);
             holder.gp = (TextView) viewCM.findViewById(R.id.vGp);
             holder.salesValue = (TextView) viewCM.findViewById(R.id.vSalesValue);
             holder.quantity = (TextView) viewCM.findViewById(R.id.vQuantity);
             holder.transactionCount = (TextView) viewCM.findViewById(R.id.vTrans);
             holder.avgPrice = (TextView) viewCM.findViewById(R.id.vAvgPrice);
             holder.objectName = (TextView) viewCM.findViewById(R.id.vObjectName);
             holder.objectCode = (TextView) viewCM.findViewById(R.id.vObjectCode);

             holder.salesValue.setText(searchArrayList.get(position).getSalesValue());
             holder.quantity.setText(searchArrayList.get(position).getQuantity());
             holder.transactionCount.setText(searchArrayList.get(position).getTransactionCount());
             holder.avgPrice.setText(searchArrayList.get(position).getAvgPrice());     
             holder.objectName.setText(searchArrayList.get(position).getObjectName());
             holder.objectCode.setText(searchArrayList.get(position).getObjectCode());

             holder.salesCost.setText(searchArrayList.get(position).getSalesCost());
            holder.profit.setText(searchArrayList.get(position).getProfit());
             holder.gp.setText(searchArrayList.get(position).getProfitMargin());

             masterView = viewCM;

             viewCM.setTag(holder);
         } else {

         }
    }

    if(null != masterView)
    holder = (ViewHolder) masterView.getTag();

    if(0 == position % 2)
        masterView.setBackgroundResource(R.color.textColorWhite);
    else
        masterView.setBackgroundResource(R.color.textColorCyan);

    return masterView;
}

So here is what happens. User clicks the button from TabA or B to TabC. This will add TestClass to current activity of the tab. Using requestID variable, adapter provides different data to TestClass in TabA and TabB. However, if I switch between tabs, all of them have the same value!

Hope I did not confuse. Please ask in case you have queries. What do you think is blocking?

Was it helpful?

Solution

AFAIK, you are using a single collection i.e. searchArrayList as I can see in your posted code.

You have to maintain its state properly to get around with the solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top