Я следую за курсом Udacity (How to use a Content Provider). Есть фрагмент кода, который меня удивил.Где предопределенные TextViews находятся в Android SDK?
Вот определение класса:
public class MainActivity extends ActionBarActivity {
private static final String[] COLUMNS_TO_BE_BOUND = new String[]{
Words.WORD,
Words.FREQUENCY,
};
private static final int[] LAYOUT_ITEMS_TO_FILL = new int[]{
android.R.id.text1,
android.R.id.text2,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get the TextView which will be populated with the Dictionary ContentProvider data.
ListView dictListView = (ListView) findViewById(R.id.dictionary_list_view);
// Get the ContentResolver which will send a message to the ContentProvider
ContentResolver resolver = getContentResolver();
// Get a Cursor containing all of the rows in the Words table
Cursor cursor = resolver.query(UserDictionary.Words.CONTENT_URI, null, null, null, null);
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this,
android.R.layout.two_line_list_item,
cursor,
COLUMNS_TO_BE_BOUND,
LAYOUT_ITEMS_TO_FILL,
0);
dictListView.setAdapter(cursorAdapter);
}
и вот файл макета:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/dictionary_list_view">
</ListView>
</LinearLayout>
Теперь, это работает отлично, несмотря на то, что я не объявил никаких TextViews именованные text1 и text2.
Когда я нажимаю правой кнопкой мыши, скажем, text1 и говорю перейти к объявлению, я перехожу к [userprofile]\AppData\Local\Android\Sdk\platforms\android-21\data\res\values\ids.xml
, и я вижу, что там определен идентификатор TextViews.
Мой главный вопрос: где эти текстовые объекты (и куча других представлений в файле ids.xml) фактически определены? Могу ли я изменить их?
Мой второй вопрос: какой разумный подход использовать TextView, который я определил? Должен ли я определить его в файле activity_main.xml или я должен поместить его в другой файл макета?
Спасибо. Вы знаете, где я могу найти исходный файл для этих стандартных ресурсов? Просто из любопытства. – SercioSoydanov
Например, тот, который вы используете, находится в './Frameworks/base/core/res/res/layout/two_line_list_item.xml' –