آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

خطا در ست کردن adapter به lst_content.setAdapter(adapter)

وحید گروسی  9 سال پیش  9 سال پیش
0 0

با سلام در انجام آموزش لیست ویو آموزش قدیم اندروید (من تو محیط اندروید استودیو کد زدم من) هنگام ست کردن مقدار به ارور زیر بر میخورم از چی ایراد می گیره ؟

Error:(24, 15) error: no suitable constructor found for ArrayAdapter(ArrayList<StructNote>)
constructor ArrayAdapter.ArrayAdapter(Context,int) is not applicable
(actual and formal argument lists differ in length)
constructor ArrayAdapter.ArrayAdapter(Context,int,int) is not applicable
(actual and formal argument lists differ in length)
constructor ArrayAdapter.ArrayAdapter(Context,int,Object[]) is not applicable
(actual and formal argument lists differ in length)
constructor ArrayAdapter.ArrayAdapter(Context,int,int,Object[]) is not applicable
(actual and formal argument lists differ in length)
constructor ArrayAdapter.ArrayAdapter(Context,int,List) is not applicable
(actual and formal argument lists differ in length)
constructor ArrayAdapter.ArrayAdapter(Context,int,int,List) is not applicable
(actual and formal argument lists differ in length)

+1 0
با constructor مشکل داره .من یه کم متفاوت از تعریف استاد لیست ویو می سارم ولی چک کنین ببینین توکلاسی که براش constructor تعریف کردین پارامترهای ورودیش درست باشه و جایی هم که ازش استفاده کردین درست ( حتی ترتیب هم مهم هست ) بهش ورودی داده باشین . (9 سال پیش)
+1 0
دقیقاً مشابه کد استاد هستش امکان این هست که استاد با اکلیپس می نویسن من با اندروید استودیو با هم فرق کنه ؟ (9 سال پیش)
+1 0
نه این جا ربطی نداره چون خود من هم تو اندروید استودیو کد می زنم . (9 سال پیش)
+1 0
ممنونم از این که پاسخ سوالای من رو میدین واقعا ممنونم (9 سال پیش)
+1 0
خاهش می کنم ، این جا هستیم تا به هم کمک کنیم . من خودم هم تازه کارم . می فهمم حتی یه لینک یا یه حدس از طرف بقیه چه قدر مهم وارزشمند هست :) (9 سال پیش)
0 0
فکر کنم اکلیپس با استیدیو فرق بکنه ولی به هر حال کدتونو خوانا نیست (9 سال پیش)
 برای این سوال 4 پاسخ وجود دارد.
پاسخ به سوال 
Hajhosseini  9 سال پیش
+2 0

شما adapter رو در بالای صفحه از نوع ArrayAdapter تعریف کردی. چرا در پایین وقتی new کردی، از AdapterNote استفاده کردی؟ 

بالایی رو هم به AdapterNote تغییر بده، مشکلت حل میشه.

0 0
در زیر تمامی محتویات فایل هارو قرار دادم ولی بازم کرش کرد نمیدونم کجاش ایراد میگیره میگه نوع داده با lst content همخونی نداره ؟؟ ولی چرا ؟ (9 سال پیش)
پاسخ به سوال 
وحید گروسی  9 سال پیش
0 0

کد های قسمت ActivityMain

package app.developer.listviewtest;

import java.util.ArrayList;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;



public class ActivityMain extends Activity {

public ArrayList<StructNote> notes = new ArrayList<StructNote>();
public AdapterNote adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView lsd_content = (ListView) findViewById(R.id.lsd_content);
adapter = new AdapterNote(notes);
for (int i = 0; i < 10; i++) {
StructNote note = new StructNote();
note.title = "Title" + i;
note.description = "Description " + i;
note.done = false;
notes.add(note);
}
adapter.notifyDataSetChanged();
lsd_content.setAdapter(adapter);
}

}

کد های قسمت adapter_note.java

package app.developer.listviewtest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class adapter_notes extends AppCompatActivity {

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

کد های کلاس AdapterNote.java

package app.developer.listviewtest;


import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import java.util.ArrayList;

public class AdapterNote extends ArrayAdapter<StructNote> {

public AdapterNote(ArrayList<StructNote> array) {
super(G.context, R.layout.adapter_notes, array);
}

private static class ViewHolder {

public TextView txt_title;
public TextView txt_description;
public CheckBox chk_done;

public ViewHolder(View view) {
txt_title = (TextView) view.findViewById(R.id.txt_title);
txt_description = (TextView) view.findViewById(R.id.txt_description);
chk_done = (CheckBox) view.findViewById(R.id.chk_done);

}

public void fill(ArrayAdapter<StructNote> adapter, StructNote item, int position) {
txt_title.setText(item.title);
txt_description.setText(item.description);
chk_done.setChecked(item.done);
}
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;

StructNote item = getItem(position);
if (convertView == null) {
convertView = G.inflater.inflate(R.layout.adapter_notes, parent, false);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.fill(this, item, position);
return convertView;
}
}

کدهای قسمت StructNote

package app.developer.listviewtest;

public class StructNote {

public String title;
public String description;
public boolean done;
}
پاسخ به سوال 
Criss  9 سال پیش
0 0

این قسمت از کد

 
public class ActivityMain extends Activity {

public ArrayList<StructNote> notes = new ArrayList<StructNote>();
public AdapterNote adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView lsd_content = (ListView) findViewById(R.id.lsd_content);
adapter = new AdapterNote(notes);
for (int i = 0; i < 10; i++) {
StructNote note = new StructNote();
note.title = "Title" + i;
note.description = "Description " + i;
note.done = false;
notes.add(note);
}
adapter.notifyDataSetChanged();
lsd_content.setAdapter(adapter);
}

}
 

به این صورت عوض کنید :

 
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView lsd_content = (ListView) findViewById(R.id.lsd_content);
// adapter = new AdapterNote(notes); // اداپتر با آرایه ایی بسازید که پر از اطلاعات باشه
for (int i = 0; i < 10; i++) {
StructNote note = new StructNote();
note.title = "Title" + i;
note.description = "Description " + i;
note.done = false;
notes.add(note);
}
adapter = new AdapterNote(notes); // بعد از اینکه اطلاعات رو پر کردید اداپتر رو بسازید
lsd_content.setAdapter(adapter); // اداپتری که پر از اطلاعات هست رو به لیست ویو بدید
adapter.notifyDataSetChanged(); // حالا از اداپتر بخواید اطلاعات نمایش رو رفرش کنه

}

 

پاسخ به سوال 
وحید گروسی  9 سال پیش
0 0

بازم ارور داد :

0 0
یکبار از منوی Build پروژه رو Clean کنید (9 سال پیش)
0 0
درست نشد میخواید پروژه رو بفرستم ببینین ؟ (9 سال پیش)
0 0
اره لینکشو بزارید همینجا (9 سال پیش)
+1 0
بفرمایید لینک (9 سال پیش)
+1 0
مشکل از فایل های xml هست محتوای Main شما درون adapter_notes قرار گرفته و محتوای مربوط به adapter_notes شامل لیست ویو هست که باید درون Main باشه ، خطا از خط 31 هست که مقدار ListView نال هست (9 سال پیش)
0 0
خب من باید چیکار کنم دقیقاً ؟ مقدوره براتون که اصلاح شده رو بدین ببینم و مقایسه کنم با کد خودم (9 سال پیش)
+1 0
لینک (9 سال پیش)
+1 0
کافییه فایل های توی layout رو rename کنید با محتوای درونشون رو عوض کنید (9 سال پیش)
0 0
ممنونم از انیمیشن استفاده کردین که من تا به حال اصلا استفاده نکردم و بلد نیستم بازم ممنونم (9 سال پیش)
+1 0
از اونجایی که دارید لیست ویو رو تست و تمرین میکنید ، همین آداپتر رو میتونید به GridView هم ست کنید و باهاش GridView بسازید و هیچ فرقی با لیست ویو نمیکنه (9 سال پیش)
0 0
بازممممممم ممنونممممممممم شما ها و بچه ها انجمن چقدر خوبیننننن (9 سال پیش)

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .