-
-
Save anonymous/e19e1c844cd428eb312f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.miwok; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.widget.ListView; | |
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", "otiiko")); | |
words.add(new Word("three", "tolookosu")); | |
words.add(new Word("four", "oyyisa")); | |
words.add(new Word("five", "massokka")); | |
words.add(new Word("six", "temmokka")); | |
words.add(new Word("seven", "kenekaku")); | |
words.add(new Word("eight", "kawinta")); | |
words.add(new Word("nine", "wo’e")); | |
words.add(new Word("ten", "na’aacha")); | |
// Create an {@link WordAdapter}, whose data source is a list of {@link Word}s. The | |
// adapter knows how to create list items for each item in the list. | |
WordAdapter adapter = new WordAdapter(this, words); | |
// Find the {@link ListView} object in the view hierarchy of the {@link Activity}. | |
// There should be a {@link ListView} with the view ID called list, which is declared in the | |
// activity_numbers.xml layout file. | |
ListView listView = (ListView) findViewById(R.id.list); | |
// Make the {@link ListView} use the {@link WordAdapter} we created above, so that the | |
// {@link ListView} will display list items for each {@link Word} in the list. | |
listView.setAdapter(adapter); | |
} | |
} |
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 androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
public class WordAdapter extends ArrayAdapter {
private static final String LOG_TAG = WordAdapter.class.getSimpleName();
/**
* This is our own custom constructor (it doesn't mirror a superclass constructor).
* The context is used to inflate the layout file, and the list is the data we want
* to populate into the lists.
*
* @param context The current context. Used to inflate the layout file.
* @param Word A List of AndroidFlavor objects to display in a list
*/
public WordAdapter(Activity context, ArrayList<Word> Word) {
// 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, Word);
}
/**
* Provides a view for an AdapterView (ListView, GridView, etc.)
*
* @param position The position in the list of data that should be displayed in the
* list item view.
* @param convertView The recycled view to populate.
* @param parent The parent ViewGroup that is used for inflation.
* @return The View for the position in the AdapterView.
*/
@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 Word} object located at this position in the list
Word currentWord = getItem(position);
// Find the TextView Miwok Translation in the list_item.xml layout with the ID miwok_text_view
TextView miwokTextView = (TextView) listItemView.findViewById(R.id.miwok_text_view);
// Get the Miwok Word from the current Word object and
// set this text on the Miwok TextView
miwokTextView.setText(currentWord.getMiwokTranslation());
// Find the TextView of Default Translation in the list_item.xml layout with the ID default_text_view
TextView defaultTextView = (TextView) listItemView.findViewById(R.id.default_text_view);
// Get the version number from the current Word object and
// set this text on the Default TextView
defaultTextView.setText(currentWord.getDefaultTranslation());
return listItemView;
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WordAdabter.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.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
public class WordAdabter extends ArrayAdapter {
/**
*/
public WordAdabter(Activity context, ArrayList 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) {
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 currentWordNumber = getItem(position);
// Find the TextView in the list_item.xml layout with the ID version_name
TextView nameTextViewMiwokTranslation = listItemView.findViewById(R.id.miwok_text_view);
// Get the miwok word from the current Word object and
// set this text on the miwok TextView
nameTextViewMiwokTranslation.setText(currentWordNumber.getMiwokTranslation());
// Find the TextView in the list_item.xml layout with the ID version_name
TextView nameTextViewMiwoDefault = listItemView.findViewById(R.id.default_text_view);
// Get the default word from the current Word object and
// set this text on the default TextView
nameTextViewMiwoDefault.setText(currentWordNumber.getDefaultTranslation());
return listItemView;
}
}
Word.Java
package com.example.android.miwok;
import android.content.Context;
import android.widget.TextView;
public class Word{
private String mDefaultTranslation;
private String mMiwokTranslation;
public Word(String defaultTranslation,String miwokTranslation){
mDefaultTranslation = defaultTranslation;
mMiwokTranslation= miwokTranslation;
}
public String getDefaultTranslation(){
return mDefaultTranslation;
}
public String getMiwokTranslation(){
return mMiwokTranslation;
}
}
XML list_item
NumberActivtiy.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.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
public class WordAdabter extends ArrayAdapter {
/**
*/
public WordAdabter(Activity context, ArrayList 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) {
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 currentWordNumber = getItem(position);
// Find the TextView in the list_item.xml layout with the ID version_name
TextView nameTextViewMiwokTranslation = listItemView.findViewById(R.id.miwok_text_view);
// Get the miwok word from the current Word object and
// set this text on the miwok TextView
nameTextViewMiwokTranslation.setText(currentWordNumber.getMiwokTranslation());
// Find the TextView in the list_item.xml layout with the ID version_name
TextView nameTextViewMiwoDefault = listItemView.findViewById(R.id.default_text_view);
// Get the default word from the current Word object and
// set this text on the default TextView
nameTextViewMiwoDefault.setText(currentWordNumber.getDefaultTranslation());
return listItemView;
}
}
So here you can find you Mistake as you know before the code as threaded chain