PDA

View Full Version : تغییر یک متغیر در کلاس دیگر



ashkan_gorg
شنبه 04 مرداد 1393, 16:55 عصر
با سلام
من یک متغیر str با نام aa در کلاس mainactivity دارم که متن پیش فرضش هست "سلام" می خواهم از کلاس custom دستوری بنویسم که متغییر aa متن پیشفرضش تغییر کنه خدا حافظ باید از چه دستوری استفاده کنم؟

NeoFighT
شنبه 04 مرداد 1393, 17:24 عصر
سلام
باید متغیر رو public و static تعریف کنی :

public static String aa = "سلام";

توی کلاس custom اینجوری مقدار دهی کنیش :

MainActivity.aa = "خدا حافظ";

ashkan_gorg
شنبه 04 مرداد 1393, 18:12 عصر
حالا من یک دیتابیس دارم که میخوام زمانی که فیلتر انجام داد اطلاعات فیلد city را درون یک متغیر قرار بده هرکاری میکنم نمیشه.میشه کمکم کنید.

db = new MyDatabase(this);







Cursor c = MyDatabase.db_object.rawQuery("select id,center,city,code from population ORDER BY center" , null);


center = new String[c.getCount()];
city = new String[c.getCount()];
code= new String[c.getCount()];


int a = 0;
if (c.moveToFirst())
{

do
{

try {


center[a] = c.getString(c.getColumnIndex("center"));
city[a] = c.getString(c.getColumnIndex("city"));
code[a] = c.getString(c.getColumnIndex("code"));
a++;



} catch (Exception e) {

e.printStackTrace();
}
}
while (c.moveToNext());
}










// Locate the ListView in listview_main.xml
//list = (ListView) findViewById(R.id.listview);

for (int i = 0; i < center.length; i++)
{
WorldPopulation wp = new WorldPopulation(center[i], city[i],
code[i]);
// Binds all strings into an array
arraylist.add(wp);
}

// Pass results to ListViewAdapter Class
adapter = new ListViewAdapter(this, arraylist);
// Binds the Adapter to the ListView
//list.setAdapter(adapter);

// Locate the EditText in listview_main.xml
editsearch = (EditText) findViewById(R.id.search);
dada = "";
adapter.filter(dada);