2017-01-01 12 views
0

まずは誰もがハッピーニューイヤー!!第2に、ソメーンがこの問題で私を助けることができるかどうかを知りたい。私はすべての行がバッチ番号を選択するスピナーを持っているListActivityを持っています。私はachiveたいものスピナーで選択した後にメソッドを起動します

<?xml version="1.0" encoding="utf-8"?> 
<com.picking.utils.RelativeLayout 
android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/relativeLayoutPickingRow"                  
android:layout_width="match_parent" 
android:layout_height="70dp"         
android:descendantFocusability="blocksDescendants" 
android:orientation="horizontal" 
> 

<LinearLayout 
    android:id="@+id/linearLayoutPickingRow" 
    android:layout_width="match_parent" 
    android:layout_height="70dp" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:baselineAligned="false" 
    android:orientation="horizontal" 
    android:paddingLeft="10dp" 
    > 

//TextViews and other things 

    <Spinner 
     android:id="@+id/spinnerLote" 
     android:layout_width="200dp" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="5dp" 
     android:layout_marginLeft="30dp" 
     android:layout_marginRight="40dp" 
     android:layout_marginTop="5dp" 
     android:background="@drawable/spinner_bg" 
     android:focusable="false" 
     android:spinnerMode="dialog" 
     android:visibility="visible" 

     /> 

</LinearLayout> 

bacthnumberが

protected void onListItemClick(ListView l, View view, int position, long id) 

を選択したときにonListItemClick方法を「シミュレート」することである私もホルダーパターンを持つリストのカスタムスピナーアダプタおよびカスタムアダプタを持っています

package com.picking.adapters; 

import android.app.Activity; 
import android.content.res.Resources; 
import android.graphics.Typeface; 
import android.text.Spannable; 
import android.text.SpannableString; 
import android.text.style.StyleSpan; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.MotionEvent; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.TextView; 
import com.picking.POJOS.LotesAbiertos; 
import com.pickingR; 
import java.util.ArrayList; 

public class SpinnerCustomAdapter<L> extends ArrayAdapter<LotesAbiertos> { 
    private ArrayList<LotesAbiertos> list; 
    private Activity context; 
    Resources resources; 
    public SpinnerCustomAdapter(Activity activity, int resource, int textViewResourceId, ArrayList<LotesAbiertos> list) { 
     super(activity, resource, textViewResourceId, list); 
     this.list = list; 
     this.context = activity; 
     resources = activity.getResources(); 
    } 

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

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     LayoutInflater inflater = context.getLayoutInflater(); 
     View row = inflater.inflate(R.layout.custom_spinner, parent, false); 
     LotesAbiertos item = list.get(position); 
     TextView tvLote = (TextView) row.findViewById(android.R.id.text1); 
     if (item != null) { // Parse the data from each object and set it. 
      if (item.status.equalsIgnoreCase("2")) { 
       tvLote.setText("SIN LOTES"); 
      } else { 
       tvLote.setText(item.loteFormateado); 
      } 
     } 
     return row; 
    } 

    @Override 
    public View getDropDownView(int position, View convertView, ViewGroup parent) { // This view starts when we click the spinner. 
     final int positionRow = position; 
     View row = convertView; 
     if (row == null) { 
      LayoutInflater inflater = context.getLayoutInflater(); 
      row = inflater.inflate(R.layout.custom_spinner_drop, parent, false); 
     } 
     TextView tvLote = (TextView) row.findViewById(android.R.id.text1); 
     TextView tvAcceso = (TextView) row.findViewById(android.R.id.text2); 
     LotesAbiertos item = list.get(position); 
     if (item != null) { // Parse the data from each object and set it. 
      if (position == 0) { 
       tvLote.setText("Lotes"); 
       row.setBackgroundColor(resources.getColor(R.color.green_ligth)); 
      } else { 
       if (item.status.equalsIgnoreCase("2")) { 
        tvLote.setText("SIN LOTES"); 
       } else { 
        tvLote.setText(item.loteFormateado.substring(0, 5)); 
        Spannable secondWord = new SpannableString(item.loteFormateado.substring(item.loteFormateado.length() - 3)); 
        secondWord.setSpan(new StyleSpan(Typeface.BOLD), 0, secondWord.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
        tvLote.append(secondWord); 
       } 
       row.setBackgroundColor(resources.getColor(R.color.white)); 
      } 
      if (item.status.equalsIgnoreCase("0") || item.status.equalsIgnoreCase("2")) { 
       tvLote.setTextColor(resources.getColor(R.color.green_dark)); 
       tvAcceso.setVisibility(View.INVISIBLE); 
      } else { 
       tvLote.setTextColor(resources.getColor(R.color.dark_grey)); 
       tvAcceso.setVisibility(View.VISIBLE); 
      } 
     } 
     return row; 
    } 
} 

私はアダプタと、それが保護されているように私は、メソッドを呼び出すcan`t異なるパッケージで活性を有する考えると、私は、このようなメソッドを持つことができます。

public void fireOnListItemClick(View view, int position, long id) { 
    onListItemClick(getListView(), view, position, id); 
} 

私はspinnnerアダプタからこのメソッドを呼び出すことができますが、問題は、私はメソッドに渡すために、リストビューの列の

view, position, id 

パラメータを取得する方法ですか?私はスピナー・アダプターにこのようなsetOnClickListenerを持っていますか?あなたの時間

答えて

0

を事前に

@Override 
public View getDropDownView(int position, View convertView, ViewGroup parent) { 

    /*..........*/ 

    row.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      /*Call fireOnListItemClick*/ 
     } 
    }); 
    return row; 
} 

おかげでOnItemSelectedListener

Example usage

spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 
     @Override 
     public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { 
      tv.setText("Spinner selected : "); 
      tv.setText(tv.getText() + parent.getItemAtPosition(position).toString()); 
     } 

     @Override 
     public void onNothingSelected(AdapterView<?> parent) { 
      //Another interface callback 
     } 
    }); 
+0

どうもありがとうを見てください。私はそれを試してみましょう。 – pburgov

関連する問題