ورود

View Full Version : توضیح در مورد پارامترهای یک متد



harani
چهارشنبه 29 آذر 1391, 19:38 عصر
سلام دوستان با توجه به کد پایین بگید که در قسمت


SimpleCursorAdapter notes = newSimpleCursorAdapter(this, R.layout.notes_row, mNotesCursor, from, to);//a

Context (که در اینجا this است) دقیقاً چی و به چه بدردی میخوره و کارش چی ؟؟؟؟ و

آرایه to به چه دردی میخوره و کارش چی ؟؟



privatevoidfillData() { //k
// Get all of the rows from the database and create the item list
Cursor mNotesCursor = mDbHelper.fetchAllNotes(); //f
startManagingCursor(mNotesCursor); //h
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = newString[]{NotesDbAdapter.KEY_TITLE, NotesDbAdapter.KEY_BODY}; //d
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = newint[]{R.id.text1, R.id.text2}; //c
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
newSimpleCursorAdapter(this, R.layout.notes_row, mNotesCursor, from, to); //b
setListAdapter(notes); //a
}



با سپاس از همگی

harani
جمعه 01 دی 1391, 11:07 صبح
دوستان میخواستم بدونم دقیقاً Contex چی و چی کار میکنه ؟؟

Nevercom
جمعه 01 دی 1391, 13:38 عصر
Parameters:

context The context where the ListView associated with this SimpleListItemFactory is running

layout resource identifier of a layout file that defines the views for this list item. The layout file should include at least those named views defined in "to"

c The database cursor. Can be null if the cursor is not available yet.

from A list of column names representing the data to bind to the UI. Can be null if the cursor is not available yet.

to The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter. Can be null if the cursor is not available yet.

flags Flags used to determine the behavior of the adapter, as perCursorAdapter.CursorAdapter(Context, Cursor, int) (http://barnamenevis.org/%E2%98%82=Petroleum/%5C/home%5C/nevercom%5C/android-sdk-linux%5C/platforms%5C/android-16%5C/android.jar%3Candroid.widget(SimpleCursorAdapter.c lass%E2%98%83SimpleCursorAdapter~SimpleCursorAdapt er~Landroid.content.Context;~I~Landroid.database.C ursor;~%5C%E2%98%83Ljava.lang.String;~%5C%E2%98%83 I~I%E2%98%82CursorAdapter%E2%98%82CursorAdapter%E2 %98%82Context%E2%98%82Cursor%E2%98%82int).
Context باید به Activity ئی اشاره کنه که ListViewی مورد نظر تعریف شده.
آرایه ی to هم لیستی از Viewهایی که همه باید از نوع TextView باشن، هست. در آرایه ی from لیستی از فیلدهایی رو اطلاعاتش رو میخاید نمایش بدید تعیین می کنید. هرکدوم از فیلد های آرایه ی from، به ترتیب در TextViewهای تعیین شده در آرایه ی to نمایش داده میشن.

Modernidea
جمعه 01 دی 1391, 23:19 عصر
سلام

کلا Context یک رابط هست که اجازه دسترسی به منابع خاص، کلاس ها و اطلاعاتی در باره فضای برنامه را میده.
Activity ها Service ها همچنین برای اینکه از همه متدها(توابع) Context ارث ببرند، تمعمیم یافته(extend) از Context هستند تا به اطالاعات فضایی که برنامه در آن در حال اجراست دسترسی داشته باشند.

موفق باشید.