0

ListView にカスタム配列アダプターを実装しましたが、提供されたコレクション内のアイテムを反復処理することはありません。HistoryCustomArrayAdapter に渡される引数の位置/インデックスは常に 0 です。リストを反復処理するにつれてこの数値が増加し、コレクション内の正しいアイテムを選択してビューを生成できると期待しています。

私は多数の異なる実装 (ListFragment) を試しましたが、常に同じポイントに到達します。私のログには、コレクション内の正しい数のアイテムが HistoryCustomArrayAdapter に渡されていることが示されているため、レンダリングに間に合うようにデータが読み込まれないという問題はないと思います。関連するログを以下に添付しました。

public class HistoryActivity extends BaseMenuActivity implements BaseMenuFragment.OnBaseMenuClickListener{

  private static final Logger logger = LoggerFactory.getLogger(HistoryActivity.class.getSimpleName());


  private void initializeDefaultView(Bundle savedInstanceState){
    FragmentUtils.applyContentAndTitleFragments(this, new HistoryContentFragment(), new HistoryMenuFragment());
  }

  @Override
  protected void onResume() {
    super.onResume();
        setHistoryButtionActive(findViewById(R.id.base_menu_fragement_container));
  }

  @Override
  public void onAttachedToWindow() {
    // TODO Auto-generated method stub
    super.onAttachedToWindow();
        setHistoryButtionActive(findViewById(R.id.base_menu_fragement_container));
  }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_main);
        initializeDefaultView(savedInstanceState);
    }


}


public class HistoryContentFragment extends Fragment{

    private static final Logger logger = LoggerFactory.getLogger(HistoryContentFragment.class.getSimpleName());

    public HistoryContentFragment() {
        super();
    }

  @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      logger.debug("Creating custom history content view");
      View view = inflater.inflate(R.layout.history_content_fragement, container, false);

      ListView listview = (ListView) view.findViewById(R.id.history_items_list_container);
      List<Custom> customs = getAllCustoms();
      logger.debug("Count of customs to add to adapter ["+customs.size()+"]");
      HistoryCustomArrayAdapter adapter = new HistoryCustomArrayAdapter(getActivity(), R.layout.history_item_fragment, customs);
      listview.setAdapter(adapter);
      return view;
    }

    private static List<Custom> getAllCustoms(){
      List<Custom> customs = new Select().from(Custom.class).execute();
      return customs;
    }
}


public class HistoryCustomArrayAdapter extends ArrayAdapter<Custom>{

  private static final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
  private static final SimpleDateFormat timeFormat = new SimpleDateFormat("h:mm a");

  private static final Logger logger = LoggerFactory.getLogger(HistoryCustomArrayAdapter.class.getSimpleName());

  private final Context context;
  private final List<Custom> values;
  private int textViewResourceId;

  public class ViewHolder {
    ImageView activityImage;
    TextView locationText;
    TextView dateText;
    TextView timeText;

  }

  public HistoryCustomArrayAdapter(Context context, int textViewResourceId, List<Custom> values) {
      super(context, textViewResourceId, values);
      this.context = context;
      this.textViewResourceId = textViewResourceId;
      this.values = values;
      logger.debug("Initialized from this constructor");
  }

  /**
   * The number of items in the list is determined by the number of speeches
   * in our array.
   *
   * @see android.widget.ListAdapter#getCount()
   */
  public int getCount() {
      return values.size();
  }

  /**
   * Since the data comes from an array, just returning the index is
   * sufficent to get at the data. If we were using a more complex data
   * structure, we would return whatever object represents one row in the
   * list.
   *
   * @see android.widget.ListAdapter#getItem(int)
   */
  public Custom getItem(int position) {
      return values.get(position);
  }

  /**
   * Use the array index as a unique id.
   *
   * @see android.widget.ListAdapter#getItemId(int)
   */
  public long getItemId(int position) {
      return position;
  }


  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    logger.debug("Position ["+position+"]\n"+this.getCount());
    ViewHolder holder;
    Custom Custom = getItem(position);
    if (convertView == null) {
      LayoutInflater inflater = LayoutInflater.from(context);
      convertView = (ViewGroup) inflater.inflate(textViewResourceId, null);

      holder = new ViewHolder();
      holder.activityImage = (ImageView) convertView.findViewById(R.id.history_item_activity_btn);
      holder.dateText = (TextView) convertView.findViewById(R.id.history_item_date);
      holder.timeText = (TextView) convertView.findViewById(R.id.history_item_time);
      holder.locationText = (TextView) convertView.findViewById(R.id.history_item_location);

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    addCustomLocation(Custom,holder);
    addCustomThumbs(Custom,holder);
    addCustomActivity(Custom,holder);
    addRtatingTimeDate(Custom,holder);
    return convertView;
  }

  private void addCustomThumbs(Custom Custom, ViewHolder viewHolder){

  }

  private void addCustomConnectionType(Custom Custom, ViewHolder viewHolder){

  }

  private void addCustomActivity(Custom Custom, ViewHolder viewHolder){

  }

  private void addRtatingTimeDate(Custom Custom, ViewHolder viewHolder){
  }

  private void addCustomLocation(Custom Custom, ViewHolder viewHolder){

  }

}

問題のあるメイン レイアウト リソース (activity_main.xml)

<ScrollView
    android:id="@+id/main_content_fragement_scrolling_container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

  <LinearLayout
      android:id="@+id/main_content_fragement_container"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical" >

    </LinearLayout>
</ScrollView>

SOLUTION MAIN LAYOUT history_activity.xml (独自のレイアウト リソースにプルし、ScrollView を削除します):

<LinearLayout
    android:id="@+id/main_content_fragement_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

</LinearLayout>

使用中のフラグメント。はい、フラグメントのスペルが間違っていることは知っています...どこでもそうです:)

history_content_fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/history_activity_container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingBottom="100dp"
    android:paddingTop="60dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:orientation="vertical">

    <ListView
        android:id="@+id/history_items_list_container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>

history_item_fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

  <RelativeLayout
      android:id="@+id/history_item_general_info"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" >

      <ImageView
          android:id="@+id/history_item_peg_pin"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:paddingRight="5dp"
          android:paddingBottom="5dp"
          android:src="@drawable/tnd_peg_pin" />

      <TextView
          android:id="@+id/history_item_location"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignTop="@id/history_item_peg_pin"
          android:layout_toRightOf="@id/history_item_peg_pin"
            style="@style/HistoryHeaderLiteTheme" />
  </RelativeLayout>

  <RelativeLayout
      android:id="@+id/history_item_details"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" >

      <RelativeLayout
          android:id="@+id/history_item_activity_type"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignTop="@id/history_item_connection_type"
          android:layout_toRightOf="@id/history_item_connection_type" >

          <ImageButton
              android:id="@+id/history_item_activity_btn"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" />
      </RelativeLayout>

      <TextView
          android:id="@+id/history_item_date"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignTop="@id/history_item_activity_type"
          android:layout_alignParentRight="true"
            style="@style/HistoryLiteTheme" />

      <TextView
          android:id="@+id/history_item_time"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@id/history_item_date"
          android:layout_alignParentRight="true"
            style="@style/HistoryLiteTheme" />
  </RelativeLayout>
</LinearLayout>

ログ:

05-07 12:21:54.604: D/AbsListView(10938): Get MotionRecognitionManager
05-07 12:21:54.614: D/HistoryContentFragment(10938): Count of custom to add to adapter [5]
05-07 12:21:54.614: D/HistoryCustomArrayAdap*(10938): Initialized from this constructor
05-07 12:21:54.624: D/HistoryMenuFragment(10938): onStart
05-07 12:21:54.624: D/HistoryMenuFragment(10938): onResume
05-07 12:21:54.644: D/HistoryCustomArrayAdap*(10938): Position [0]
05-07 12:21:54.644: D/HistoryCustomArrayAdap*(10938): 5
05-07 12:21:54.654: D/HistoryCustomArrayAdap*(10938): Position [0]
05-07 12:21:54.654: D/HistoryCustomArrayAdap*(10938): 5
05-07 12:21:54.694: D/HistoryCustomArrayAdap*(10938): Position [0]
05-07 12:21:54.694: D/HistoryCustomArrayAdap*(10938): 5
05-07 12:21:54.704: D/HistoryCustomArrayAdap*(10938): Position [0]
05-07 12:21:54.704: D/HistoryCustomArrayAdap*(10938): 5
05-07 12:21:54.704: D/HistoryCustomArrayAdap*(10938): Position [0]
05-07 12:21:54.704: D/HistoryCustomArrayAdap*(10938): 5
05-07 12:21:54.724: D/HistoryCustomArrayAdap*(10938): Position [0]
05-07 12:21:54.724: D/HistoryCustomArrayAdap*(10938): 5
05-07 12:21:54.734: D/HistoryCustomArrayAdap*(10938): Position [0]
05-07 12:21:54.734: D/HistoryCustomArrayAdap*(10938): 5
05-07 12:21:54.794: D/HistoryCustomArrayAdap*(10938): Position [0]
05-07 12:21:54.794: D/HistoryCustomArrayAdap*(10938): 5
05-07 12:21:54.804: D/HistoryCustomArrayAdap*(10938): Position [0]
05-07 12:21:54.804: D/HistoryCustomArrayAdap*(10938): 5
4

0 に答える 0