2016-07-15 10 views
0

私はUdacityのAndroidのMultiscreenアプリコースからAndroid ArrayAdapterを学習しようとしています。私はコースで言及したようにすべてをやったが、リストビューを見ることができない。また、アンドロイドスタジオから何のエラーも受け取りません。ここでAndroidで表示されないコンテンツのリストArrayAdapterの例

は私codes-ある

NumbersActivity.java

package com.example.android.miwok; 

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.widget.ArrayAdapter; 
import android.widget.LinearLayout; 
import android.widget.ListView; 
import android.widget.TextView; 

import java.util.ArrayList; 

public class NumbersActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_numbers); 

     // Create a list of words 
     ArrayList<Word> words = new ArrayList<Word>(); 

     words.add(new Word("one","lutti")); 
     words.add(new Word("two","otikko")); 
     words.add(new Word("three","tolokooosu")); 
     words.add(new Word("four","oyyisa")); 
     words.add(new Word("five","massokka")); 
     words.add(new Word("six","temmokka")); 
     words.add(new Word("seven","kenakaku")); 
     words.add(new Word("eight","kawinta")); 
     words.add(new Word("nine","woe")); 
     words.add(new Word("ten","naaaache")); 


     WordAdapter adapter = new WordAdapter(this, words); 

     ListView listView = (ListView) findViewById(R.id.list); 

     listView.setAdapter(adapter); 

    } 
} 

WordAdapter.java

package com.example.android.miwok; 

import android.app.Activity; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.ImageView; 
import android.widget.TextView; 

import java.util.ArrayList; 

/** 
* Created by opsol on 15/7/16. 
*/ 
public class WordAdapter extends ArrayAdapter<Word> { 

    public WordAdapter(Activity context, ArrayList<Word> words) { 
     // Here, we initialize the ArrayAdapter's internal storage for the context and the list. 
     // the second argument is used when the ArrayAdapter is populating a single TextView. 
     // Because this is a custom adapter for two TextViews and an ImageView, the adapter is not 
     // going to use this second argument, so it can be any value. Here, we used 0. 
     super(context, 0, words); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     // Check if the existing view is being reused, otherwise inflate the view 
     View listItemView = convertView; 
     if(listItemView == null) { 
      listItemView = LayoutInflater.from(getContext()).inflate(
        R.layout.list_item, parent, false); 
     } 

     // Get the {@link AndroidFlavor} object located at this position in the list 
     Word currentWord = getItem(position); 

     // Find the TextView in the list_item.xml layout with the ID version_name 
     TextView miwokTextView = (TextView) listItemView.findViewById(R.id.miwok_text_view); 
     // Get the version name from the current AndroidFlavor object and 
     // set this text on the name TextView 
     miwokTextView.setText(currentWord.getmMiwokTranslation()); 

     // Find the TextView in the list_item.xml layout with the ID version_number 
     TextView defaultTextView = (TextView) listItemView.findViewById(R.id.default_text_view); 
     // Get the version number from the current AndroidFlavor object and 
     // set this text on the number TextView 
     defaultTextView.setText(currentWord.getDefaultTranslation()); 

     return listItemView; 
    } 
} 

Word.java

package com.example.android.miwok; 

/** 
* Created by opsol on 15/7/16. 
*/ 
public class Word { 
    private String mDefaultTranslation; 
    private String mMiwokTranslation; 

    public Word(String mDefaultTranslation, String mMiwokTranslation){ 
     mDefaultTranslation = mDefaultTranslation; 
     mMiwokTranslation = mMiwokTranslation; 
    } 

    public String getDefaultTranslation(){ 
     return mDefaultTranslation; 
    } 

    public String getmMiwokTranslation(){ 
     return mMiwokTranslation; 
    } 
} 

list_item.xml

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

    <TextView 
     android:id="@+id/miwok_text_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="lutti" /> 

    <TextView 
     android:id="@+id/default_text_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="one" /> 

</LinearLayout> 

activity_numbers.xml

<?xml version="1.0" encoding="utf-8"?> 
<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/list" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_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" 
    tools:context="com.example.android.miwok.NumbersActivity"> 

</ListView> 

私のリストビューのスクリーンショット -

enter image description here

誰でもここで何が間違っているのか理解してもらえますか?

よろしく

答えて

0

あなたのワードクラスのコンストラクタは、返信用この

public Word(String mDefaultTranslation, String mMiwokTranslation) { 
     this.mDefaultTranslation = mDefaultTranslation; 
     this.mMiwokTranslation = mMiwokTranslation; 
    } 
+0

おかげのようになります。出来た。しかし、何がエラーでしたか?これ以前にも、私は多くの場所でJavaのオブジェクトプロパティにアクセスする必要はありません。さらに、Android Studioでは構文エラーが表示されませんでした。 – mi6crazyheart

+0

http://www.java-samples.com/showtutorial.php?tutorialid=144このリンクを確認してください! –

+0

入手できます。この情報をありがとう。 – mi6crazyheart

関連する問題