scientific

توسعه دهنده اندروید
  • تعداد ارسال ها

    98
  • تاریخ عضویت

  • آخرین بازدید

اعتبار در انجمن

5 Neutral

درباره scientific

  • درجه
    توسعه دهنده فعال

آخرین بازدید کنندگان نمایه

284 بازدید کننده نمایه
  1. ممنون ولی من قبلا برنامم مشکل داشت و پیغام میداد که متد run proguard رو پیدا نمیکنه Gradle DSL method not found: 'runProguard()' Android Studio Could not find method runProguard() for arguments ... برای رفعش باید modifyEnable رو false می کردم در فایل build.gradle اما تو سایت delveloper میگه برای کم کردن حجم باید modifyEnable رو true کنم چی کار کنم
  2. با سلام من یه جا دیدم که حجم برنامه با خروجی گرفتن کم می شد یادم نیست روشش چی بود و هرچی سرچ می کنم پیدا نمی کنم ممنون میشم اگر میدونید راهنمایی کنید
  3. لیست رو بعد از پارز کردن جیسون آبجکت ها در دیتامدل پر می کنم:
  4. با سلام من در یک کلاس (api_request ) ریکوئستم رو می سازم و رسپونس رو دریافت می کنم بعد جیسون آبجکت ها رو پارز می کنم در کلاس دیتامدلم و بعد دیتامدل رو به یک لیست اد میکنم بعد یک کلاس هم نوشتم (List_jsonobject) که list رو بر می گرداند حالا می خوام مقادیر رو داخل آیتم های ریسایکلرویو نشون بدم اما اکتیویتی خالی رو نشون میده با این که تمام مراحل ساخت ریسایکلرویو،کلاسviewHolder, آداپتر و غیره رو کامل انجام دادم... من کلاس های مرتبط رو میزارم ممنون میشم راهنمایی کنید public class Api_Requests { Context context; public Api_Requests(Context context) { this.context=context; } public void get_NextFivedaysForcast(final OnRecivedWeatherListener onRecivedweatherListener, String City_Name) { JsonObjectRequest joRequest=new JsonObjectRequest(Request.Method.GET, "http://api.openweathermap.org/data/2.5/forecast?q=London,us&apikey=6204cbd647f0a0c263315edfe5b88a1a", null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { List<Weather_datamodel> list=new ArrayList<>(); ParseAndSet_Response(response); onRecivedweatherListener.OnRecivedweather(list); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("ApiService","onErrorResponse"+error.toString()); } }); joRequest.setRetryPolicy(new DefaultRetryPolicy(8000,DefaultRetryPolicy.DEFAULT_MAX_RETRIES,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); RequestQueue requestQueue=Volley.newRequestQueue(context); requestQueue.add(joRequest); } public void get_CurrentweatherForcast(OnRecivedWeatherListener onRecivedweatherListener,String City_Name) { JsonObjectRequest joRequest2=new JsonObjectRequest(Request.Method.GET, "http://api.openweathermap.org/data/2.5/weather?q=London&apikey=6204cbd647f0a0c263315edfe5b88a1a" , null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { } }); joRequest2.setRetryPolicy(new DefaultRetryPolicy(8000,DefaultRetryPolicy.DEFAULT_MAX_RETRIES,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); RequestQueue requestQueue=Volley.newRequestQueue(context); requestQueue.add(joRequest2); } ////------------------ Parse jsonObject to Datamodel -------------------//// public List_jsonobject ParseAndSet_Response(JSONObject response) { Weather_datamodel weather_datamodel=new Weather_datamodel(); List<Weather_datamodel> list=new ArrayList<>(); List_jsonobject listclass=new List_jsonobject(); try { JSONArray list_jsonarray = response.getJSONArray("list"); //create object from "List" JSONObject list_jasonobject=list_jsonarray.getJSONObject(0); JSONArray weather_jsonarray=list_jasonobject.getJSONArray("weather"); JSONObject weather_jsonobject=weather_jsonarray.getJSONObject(0); weather_datamodel.setWeather_name(weather_jsonobject.getString("main")); weather_datamodel.setWeather_description(weather_jsonobject.getString("description")); weather_datamodel.setWeather_icon(weather_jsonobject.getString("icon")); JSONObject wind_jsonobject=list_jasonobject.getJSONObject("wind"); weather_datamodel.setWind_speed((float) wind_jsonobject.getDouble("speed")); weather_datamodel.setWind_degree((float) wind_jsonobject.getDouble("degree")); JSONObject main_jsonobject=list_jasonobject.getJSONObject("mian"); weather_datamodel.setTempreture((float) main_jsonobject.getDouble("temp")); weather_datamodel.setTempreture_min((float) main_jsonobject.getDouble("temp_min")); weather_datamodel.setTempreture_max((float) main_jsonobject.getDouble("temp_max")); weather_datamodel.setPressure((float) main_jsonobject.getDouble("pressure")); weather_datamodel.setHumidity((int) main_jsonobject.getDouble("humidity")); // set datamodel to List list.add(weather_datamodel); Log.i("TAG","_____size of List:____"+list.size()); return listclass; } catch (JSONException e) { e.printStackTrace(); return null; } } public interface OnRecivedWeatherListener { void OnRecivedweather(List<Weather_datamodel> list); } } public class List_jsonobject { public List<Weather_datamodel> getData() { Weather_datamodel weather_datamodel = new Weather_datamodel(); List<Weather_datamodel> list =new ArrayList<>(); list.add(weather_datamodel); return list; } } public class Adapter_RecyclerView extends RecyclerView.Adapter<Items_Fivedaysforecast> { List<Weather_datamodel> list = new ArrayList<>(); Context context; public Adapter_RecyclerView(Context context,List<Weather_datamodel> list) { this.context=context; this.list=list; } @Override public Items_Fivedaysforecast onCreateViewHolder(ViewGroup parent, int viewType) { View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.items_fivedaysforecast,parent,false); Items_Fivedaysforecast items_fdf=new Items_Fivedaysforecast(view); return items_fdf; } @Override public void onBindViewHolder(Items_Fivedaysforecast holder, int position) { holder.txt_days.setText(list.get(position).getWeather_name()); } @Override public int getItemCount() { return list.size(); } } public class MainActivity extends AppCompatActivity implements Api_Requests.OnRecivedWeatherListener { Context context; List<Weather_datamodel> list=new ArrayList<>(); Adapter_RecyclerView adapter=new Adapter_RecyclerView(context,list); JSONObject jsonObject; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Api_Requests api_requests=new Api_Requests(MainActivity.this); api_requests.get_NextFivedaysForcast(MainActivity.this,"Mashhad"); //api_requests.ParseAndSet_Response(jsonObject,list); } @Override public void OnRecivedweather(List<Weather_datamodel> list) { Adapter_RecyclerView adapter=new Adapter_RecyclerView(MainActivity.this,list); RecyclerView recyclerView= (RecyclerView) findViewById(R.id.recyclerview_fiveday); //adapter=new Adapter_RecyclerView(api_requests.list); recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this)); recyclerView.setAdapter(adapter); } } آیا ارایه ای که به RecyclerView ست میکنید دارای اطلاعات میباشد؟
  5. من اشتباهی کدهای فرگمنت ها رو گذاشتم این اکتیویتیMain که فرگمنت ها رو نمایش میده: package com.narsis.countriesandcontinents.mainPage; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.graphics.Typeface; import android.media.audiofx.BassBoost; import android.net.Uri; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.NavigationView; import android.support.design.widget.TabLayout; import android.support.v4.view.GravityCompat; import android.support.v4.view.MenuItemCompat; import android.support.v4.view.ViewPager; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.Gravity; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.WindowManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TableLayout; import android.widget.TextView; import android.widget.Toast; import com.astuetz.PagerSlidingTabStrip; import com.narsis.countriesandcontinents.Adapters.ViewPagerAdapter; import com.narsis.countriesandcontinents.Africa_Fragment; import com.narsis.countriesandcontinents.America_Fragment; import com.narsis.countriesandcontinents.Asia_Fragment; import com.narsis.countriesandcontinents.Australia_Fragment; import com.narsis.countriesandcontinents.DarbareActivity; import com.narsis.countriesandcontinents.DarbareyeApp_Activity; import com.narsis.countriesandcontinents.Database; import com.narsis.countriesandcontinents.Europe_Fragment; import com.narsis.countriesandcontinents.R; import com.narsis.countriesandcontinents.Settings.Settings; import com.narsis.countriesandcontinents.Structure; import com.narsis.countriesandcontinents.search.Search; import static android.support.design.R.styleable.TabLayout; import static com.astuetz.pagerslidingtabstrip.R.styleable.PagerSlidingTabStrip; import static com.narsis.countriesandcontinents.R.id.close; import static com.narsis.countriesandcontinents.R.id.countryname; import static com.narsis.countriesandcontinents.R.id.design_navigation_view; import static com.narsis.countriesandcontinents.R.id.flag; import static com.narsis.countriesandcontinents.R.id.navigation; import static com.narsis.countriesandcontinents.R.id.start; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; import it.neokree.materialtabs.MaterialTabHost; import java.util.ArrayList; import it.neokree.materialtabs.MaterialTabHost; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.IOException; import android.provider.Settings.System; import android.support.design.widget.CollapsingToolbarLayout; public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{ Database mydatabase; SQLiteDatabase database; public static Context context; Toolbar toolbar; TabLayout mtabLayout; ViewPager viewPager; CardView cardView; ViewPagerAdapter viewPagerAdapter; AdapterCardView adaptercard; public DrawerLayout mDrawerlayout; public NavigationView navigationView; private String[] mPlanetTitles; ActionBar mActionBar; ActionBarDrawerToggle actionBarDrawerToggle; public CollapsingToolbarLayout collapsingToolbarLayout=null; Settings settings=new Settings(); //_________________________________________________________________________________________________________________________________________ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.navigation); context=getApplicationContext(); Database mydatabase = new Database(this); mydatabase.CreateDatabase(); toolbar= (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setTitle(""); mtabLayout= (TabLayout) findViewById(R.id.tablayout); viewPager= (ViewPager) findViewById(R.id.viewpager); viewPagerAdapter=new ViewPagerAdapter(getSupportFragmentManager()); viewPagerAdapter.addFragemnts(new Australia_Fragment(),"استرالیا"); viewPagerAdapter.addFragemnts(new Africa_Fragment(),"آفریقا"); viewPagerAdapter.addFragemnts(new Asia_Fragment(),"آسیا"); viewPagerAdapter.addFragemnts(new America_Fragment(),"آمریکا"); viewPagerAdapter.addFragemnts(new Europe_Fragment(),"اروپا"); viewPager.setAdapter(viewPagerAdapter); mtabLayout.setupWithViewPager(viewPager); navigationView= (NavigationView) findViewById(R.id.navigation); navigationView.setNavigationItemSelectedListener(this); mDrawerlayout= (DrawerLayout) findViewById(R.id.drawer); TextView txt_title= (TextView) findViewById(R.id.txt_title); String fontpath="fonts/B Titr Bold_0.ttf"; String fontpath2="fonts/IranNastaliq.ttf"; Typeface tp_titr=Typeface.createFromAsset(getAssets(),fontpath2); txt_title.setTypeface(tp_titr); } @Override protected void onPostCreate(@Nullable Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_item, menu); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case R.id.action_search: Intent intent= new Intent(MainActivity.this,Search.class); MainActivity.this.startActivity(intent); break; } switch (id) { case R.id.action_menu: if(mDrawerlayout.isDrawerOpen(Gravity.RIGHT)) { mDrawerlayout.closeDrawer(Gravity.RIGHT); }else{ mDrawerlayout.openDrawer(Gravity.RIGHT); } break; } return true; } @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { mDrawerlayout.closeDrawers(); switch (item.getItemId()) { case R.id.darbarema: { Intent intent = new Intent(MainActivity.this, DarbareActivity.class); startActivity(intent); return true; } case R.id.khoruj: finish(); return true; case R.id.darbareApp: { startActivity(new Intent(MainActivity.this,DarbareyeApp_Activity.class)); return true; } case R.id.Emtiaz: { try { Intent intent = new Intent(Intent.ACTION_EDIT); intent.setData(Uri.parse("bazaar://details?id=" + "com.narsis.countriesandcontinents")); intent.setPackage("com.farsitel.bazaar"); startActivity(intent); return true; } catch (Exception e) { Toast.makeText(context,"اتصال اینترنت خود را بررسی کنید و از نصب بودن بازار بر روی دستگاه خود اطمینان حاصل نمایید...",Toast.LENGTH_SHORT); } } default: return true; } } } با تشکر
  6. سلام خواهش می کنم خیلی هم ممنونم بابت پاسخ گویی... این کلاس AdapterCardView: package com.narsis.countriesandcontinents.mainPage; import android.content.Context; import android.content.res.AssetManager; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Typeface; import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; import android.text.Layout; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import com.narsis.countriesandcontinents.Africa_Fragment; import com.narsis.countriesandcontinents.Database; import com.narsis.countriesandcontinents.R; import com.narsis.countriesandcontinents.Structure; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.zip.Inflater; import static android.support.v7.widget.RecyclerView.*; import static java.security.AccessController.getContext; public class AdapterCardView extends RecyclerView.Adapter<ViewHolder> { Context context; LayoutInflater inflater; List<Structure> items = Collections.emptyList(); public int flagLoadItems=0; String pathfont="fonts/Mj_Text Bold.ttf"; Typeface tf=Typeface.createFromAsset(MainActivity.context.getAssets(),pathfont); public AdapterCardView(Context context, List<Structure> items) { this.context=context; this.items = items; inflater=LayoutInflater.from(context); setHasStableIds(false); } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_cardview,parent,false); TextView textView= (TextView) view.findViewById(R.id.txt_title); ViewHolder viewHolder= new ViewHolder(view,textView); return viewHolder; } @Override public void onBindViewHolder(ViewHolder holder, int position) { Database database=new Database(context); holder.txt_countryname.setText(items.get(position).getCountry_Name()); holder.txt_countryname.setTypeface(tf); int resID = context.getResources().getIdentifier(items.get(position).getFlag(),"mipmap", context.getPackageName()); if((items.get(position).getFlag()).equals("0")) { try { holder.img_flags.setImageBitmap(database.getBitmapFromAssets("iran.png")); } catch (IOException e) { e.printStackTrace(); } } else { holder.img_flags.setImageResource(resID); } } @Override public int getItemCount() { flagLoadItems=1; return items.size(); } @Override public long getItemId(int position) { return super.getItemId(position); } @Override public int getItemViewType(int position) { return super.getItemViewType(position); } } Fragment Asia: package com.narsis.countriesandcontinents; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.graphics.Color; import android.graphics.Typeface; import android.net.Uri; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v7.app.AlertDialog; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.afollestad.materialdialogs.DialogAction; import com.afollestad.materialdialogs.MaterialDialog; import com.github.javiersantos.materialstyleddialogs.MaterialStyledDialog; import com.narsis.countriesandcontinents.mainPage.AdapterCardView; import com.narsis.countriesandcontinents.mainPage.MainActivity; import com.narsis.countriesandcontinents.mainPage.ViewHolder; import java.io.IOException; import java.lang.reflect.Type; import java.sql.SQLException; import java.util.ArrayList; import static com.narsis.countriesandcontinents.mainPage.MainActivity.context; /** * A simple {@link Fragment} subclass. */ public class Asia_Fragment extends Fragment { RecyclerView recyclerView; public static final String ARG_PAGE = "ARG_PAGE"; private int mPage; Cursor cursor; public ArrayList<Structure> arrayList = new ArrayList<Structure>(); public AdapterCardView adapterCardView ; EditText txt_search; String newText; String s; public Asia_Fragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { ViewGroup viewGroup=(ViewGroup)inflater.inflate(R.layout.fragment_asia_,container,false);//set:recyclerView recyclerView= (RecyclerView) viewGroup.findViewById(R.id.my_recyclerview); TextView country_data = (TextView) viewGroup.findViewById(R.id.country_data); Typeface tp = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Mj_Text Bold.ttf"); adapterCardView = new AdapterCardView(getActivity(),arrayList); loadDatabase(); return viewGroup; } public void loadDatabase() { final Database database = new Database(getContext()); database.CreateDatabase(); database.openDatabase(); Cursor cursor=database.QueryData("SELECT * FROM Country WHERE Ghareh='آسیا'"); if (cursor != null) { if (cursor.moveToFirst()) { do { Structure structure = new Structure(); structure.setCountry_Name(cursor.getString(1)); structure.setCapital(cursor.getString(2)); structure.setGhareh(cursor.getString(3)); structure.setFlag(cursor.getString(4)); structure.setMeanCountry(cursor.getString(5)); arrayList.add(structure); } while (cursor.moveToNext()); recyclerView.addOnItemTouchListener( new RecyclerItemClickListener(getActivity(), recyclerView, new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Alert alert = new Alert(getActivity()); for(int i=0;i<=position;i++) { alert.country_data.setText(arrayList.get(position).getCountry_Name()); alert.capital_data.setText(arrayList.get(position).getCapital()); alert.ghareh_data.setText(arrayList.get(position).getGhareh()); alert.meancountrydata.setText(arrayList.get(position).getMeanCountry()); int id=getContext().getResources().getIdentifier(arrayList.get(position).getFlag(),"mipmap",getContext().getPackageName()); alert.imgDialog.setImageResource(id); alert.show(); } } @Override public void onLongItemClick(View view, int position) { } })); } } LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext()); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.setAdapter(adapterCardView); database.close(); } } Fragment Europe: package com.narsis.countriesandcontinents; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.narsis.countriesandcontinents.mainPage.AdapterCardView; import java.util.ArrayList; /** * A simple {@link Fragment} subclass. */ public class Europe_Fragment extends Fragment { RecyclerView recyclerView; ArrayList<Structure>arrayList=new ArrayList<>(); public Europe_Fragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view=inflater.inflate(R.layout.fragment_asia_, container, false); recyclerView = (RecyclerView) view.findViewById(R.id.my_recyclerview); AdapterCardView adapterCardView=new AdapterCardView(getContext(),arrayList); recyclerView.setAdapter(adapterCardView); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setHasFixedSize(true); loadDatabase(); return view; } public void loadDatabase(){ Database database=new Database(getContext()); database.CreateDatabase(); database.openDatabase(); Cursor cursor= database.QueryData("SELECT * FROM Country WHERE Ghareh='اروپا'"); if(cursor!=null){ if(cursor.moveToFirst()){ do { Structure structure = new Structure(); structure.setCountry_Name(cursor.getString(1)); structure.setFlag(cursor.getString(4)); structure.setCapital(cursor.getString(2)); structure.setMeanCountry(cursor.getString(5)); structure.setGhareh(cursor.getString(3)); arrayList.add(structure); } while (cursor.moveToNext()) ; recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getContext(),recyclerView, new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Alert alert = new Alert(getActivity()); for(int i=0;i<=position;i++) { alert.country_data.setText(arrayList.get(position).getCountry_Name()); alert.ghareh_data.setText(arrayList.get(position).getGhareh()); alert.capital_data.setText(arrayList.get(position).getCapital()); alert.meancountrydata.setText(arrayList.get(position).getMeanCountry()); int id=getContext().getResources().getIdentifier(arrayList.get(position).getFlag(),"mipmap",getContext().getPackageName()); alert.imgDialog.setImageResource(id); alert.show(); } } @Override public void onLongItemClick(View view, int position) { } })); } } } } Fragment America package com.narsis.countriesandcontinents; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.narsis.countriesandcontinents.mainPage.AdapterCardView; import com.narsis.countriesandcontinents.mainPage.MainActivity; import java.util.ArrayList; /** * A simple {@link Fragment} subclass. */ public class America_Fragment extends Fragment { RecyclerView recyclerView; AdapterCardView adapterCardView; ArrayList<Structure> arrayList=new ArrayList<Structure>(); Cursor cursor; public America_Fragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view= inflater.inflate(R.layout.fragment_asia_, container, false); recyclerView= (RecyclerView) view.findViewById(R.id.my_recyclerview); AdapterCardView adapterCardView=new AdapterCardView(getActivity(),arrayList); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setAdapter(adapterCardView); recyclerView.setHasFixedSize(true); loadDatabase(); return view; } public void loadDatabase(){ Database database=new Database(getActivity()); database.CreateDatabase(); database.openDatabase(); cursor= database.QueryData("SELECT * FROM Country WHERE Ghareh='آمریکا'"); if (cursor!=null){ if (cursor.moveToFirst()){ do { Structure structure=new Structure(); structure.setCountry_Name(cursor.getString(1));//sotun 1 structure.setFlag(cursor.getString(cursor.getColumnIndex("Flag"))); structure.setCapital(cursor.getString(2)); structure.setGhareh(cursor.getString(3)); structure.setMeanCountry(cursor.getString(5)); arrayList.add(structure); } while (cursor.moveToNext()); recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getContext(),recyclerView, new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Alert alert = new Alert(getActivity()); for(int i=0;i<=position;i++) { alert.ghareh_data.setText(arrayList.get(position).getGhareh()); alert.capital_data.setText(arrayList.get(position).getCapital()); alert.country_data.setText(arrayList.get(position).getCountry_Name()); alert.meancountrydata.setText(arrayList.get(position).getMeanCountry()); int id=getContext().getResources().getIdentifier(arrayList.get(position).getFlag(),"mipmap",getContext().getPackageName()); alert.imgDialog.setImageResource(id); alert.show(); } } @Override public void onLongItemClick(View view, int position) { } })); } } } } Fragment Africa: package com.narsis.countriesandcontinents; import android.content.Context; import android.content.res.AssetManager; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.narsis.countriesandcontinents.mainPage.AdapterCardView; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; /** * A simple {@link Fragment} subclass. */ public class Africa_Fragment extends Fragment { RecyclerView recyclerView; ArrayList<Structure> arrayList=new ArrayList<>(); Context context; public Africa_Fragment() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view =inflater.inflate(R.layout.fragment_asia_, container, false); recyclerView= (RecyclerView) view.findViewById(R.id.my_recyclerview); AdapterCardView adapterCardView=new AdapterCardView(getContext(),arrayList); recyclerView.setAdapter(adapterCardView); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setHasFixedSize(true); loadDatabase(); return view; } public void loadDatabase(){ Database database=new Database(getContext()); database.CreateDatabase(); database.openDatabase(); Cursor cursor=database.QueryData("SELECT * FROM Country WHERE Ghareh='آفریقا'"); if (cursor!=null && cursor.moveToFirst()) { do { Structure structure = new Structure(); structure.setCountry_Name(cursor.getString(1)); structure.setGhareh(cursor.getString(3)); structure.setCapital(cursor.getString(2)); structure.setMeanCountry(cursor.getString(5)); structure.setFlag(cursor.getString(4)); arrayList.add(structure); } while (cursor.moveToNext()); recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getContext(),recyclerView, new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Alert alert = new Alert(getActivity()); for(int i=0;i<=position;i++) { alert.country_data.setText(arrayList.get(position).getCountry_Name()); alert.ghareh_data.setText(arrayList.get(position).getGhareh()); alert.capital_data.setText(arrayList.get(position).getCapital()); alert.meancountrydata.setText(arrayList.get(position).getMeanCountry()); int id=getContext().getResources().getIdentifier(arrayList.get(position).getFlag(),"mipmap",getContext().getPackageName()); alert.imgDialog.setImageResource(id); alert.show(); } } @Override public void onLongItemClick(View view, int position) { } })); } } } Fragment Austrolia: package com.narsis.countriesandcontinents; import android.database.Cursor; import android.os.Bundle; import android.provider.ContactsContract; import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.narsis.countriesandcontinents.mainPage.AdapterCardView; import java.util.ArrayList; /** * A simple {@link Fragment} subclass. */ public class Australia_Fragment extends Fragment { RecyclerView recyclerView; ArrayList<Structure>arrayList =new ArrayList<>(); // int flag=0; AdapterCardView adapcard; public Australia_Fragment() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view= inflater.inflate(R.layout.fragment_asia_, container, false); recyclerView= (RecyclerView) view.findViewById(R.id.my_recyclerview); AdapterCardView adapterCardView = new AdapterCardView(getContext(), arrayList); recyclerView.setAdapter(adapterCardView); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setHasFixedSize(true); loadDatabase(); return view; } public void loadDatabase(){ final Database database=new Database(getContext()); database.CreateDatabase(); database.openDatabase(); Cursor cursor=database.QueryData("SELECT * FROM Country WHERE Ghareh='استرالیا'"); if (cursor!=null && cursor.moveToFirst()){ do { Structure structure = new Structure(); structure.setCountry_Name(cursor.getString(1)); structure.setFlag(cursor.getString(4)); structure.setCapital(cursor.getString(2)); structure.setGhareh(cursor.getString(3)); structure.setMeanCountry(cursor.getString(5)); arrayList.add(structure); } while (cursor.moveToNext()); recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getContext(),recyclerView, new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Alert alert = new Alert(getActivity()); for (int i=0;i<=position;i++) { alert.country_data.setText(arrayList.get(position).getCountry_Name()); alert.capital_data.setText(arrayList.get(position).getCapital()); alert.ghareh_data.setText(arrayList.get(position).getGhareh()); alert.meancountrydata.setText(arrayList.get(position).getMeanCountry()); int id=getContext().getResources().getIdentifier(arrayList.get(position).getFlag(),"mipmap",getContext().getPackageName()); alert.imgDialog.setImageResource(id); alert.show(); } database.close(); } @Override public void onLongItemClick(View view, int position) { } })); } } }
  7. من یک بریک پویت گذاشتم ابتدای متد onCerete : دفعه اول مقدار savedInstanceState صفر هست و تعداد آیتمها هم درسته ولی وقتی وارد تب دیگه میشم و بعد برمی گردم به همون تب، مقدار savedInstanceState بازم صفره!!!!!! و تعداد آیتم ها دوبرابر. دفعه سوم هم تعداد آتم ها سه برابر میشه و به همین ترتیب... (درواقع با هربار جابه جایی بین تب ها آیتم ها به آیتم های قبلی اضافه میشن.) الان این عکسی که گذاشتم مال زمانیه که یک بار وارد یک تب دیگه شدم و بعد دوباره به تب قبلی برگشتم :
  8. این کد رو نوشتم ولی متاسفانه بازم آیتم ها تکرار میشن... @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { ViewGroup viewGroup=(ViewGroup)inflater.inflate(R.layout.fragment_asia_,container,false); recyclerView= (RecyclerView) viewGroup.findViewById(R.id.my_recyclerview); TextView country_data = (TextView) viewGroup.findViewById(R.id.country_data); if (savedInstanceState == null){ adapterCardView = new AdapterCardView(getActivity(),arrayList); loadDatabase(); } return viewGroup; }
  9. من از یک متغیر هم استفاده کردم که وقتی یک بار لیست پر شده مقدارش تغییر کنه... ولی تاثیری نداشت: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { ViewGroup viewGroup=(ViewGroup)inflater.inflate(R.layout.fragment_asia_,container,false); recyclerView= (RecyclerView) viewGroup.findViewById(R.id.my_recyclerview); TextView country_data = (TextView) viewGroup.findViewById(R.id.country_data); Typeface tp = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Mj_Text Bold.ttf"); if(flag==0) { adapterCardView = new AdapterCardView(getActivity(), arrayList); flag = 1; } loadDatabase(); arrayList.add(null); return viewGroup; }
  10. با سلام من توی برنامم چندتا تب دارم که وقتی بین اونها جابه جا میشم آیتم های ریسایکلرویو تعدادشون دوبرابر میشه (از یه جایی به بعد توی لیست تکرار میشن) همچنین اگر چندبار اسکرول کنم لیست رو این اتفاق میفته... من یکی از فرگمنت ها رو میزارم ممنون میشم راهنمایی بفرمایید. کلاس Fragment package com.narsis.countriesandcontinents; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.graphics.Color; import android.graphics.Typeface; import android.net.Uri; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v7.app.AlertDialog; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.afollestad.materialdialogs.DialogAction; import com.afollestad.materialdialogs.MaterialDialog; import com.github.javiersantos.materialstyleddialogs.MaterialStyledDialog; import com.narsis.countriesandcontinents.mainPage.AdapterCardView; import com.narsis.countriesandcontinents.mainPage.MainActivity; import com.narsis.countriesandcontinents.mainPage.ViewHolder; import java.io.IOException; import java.lang.reflect.Type; import java.sql.SQLException; import java.util.ArrayList; import static com.narsis.countriesandcontinents.mainPage.MainActivity.context; /** * A simple {@link Fragment} subclass. */ public class Asia_Fragment extends Fragment { RecyclerView recyclerView; public static final String ARG_PAGE = "ARG_PAGE"; private int mPage; Cursor cursor; public ArrayList<Structure> arrayList = new ArrayList<Structure>(); public AdapterCardView adapterCardView ; EditText txt_search; String newText; String s; public Asia_Fragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { ViewGroup viewGroup=(ViewGroup)inflater.inflate(R.layout.fragment_asia_,container,false);//set:recyclerView recyclerView= (RecyclerView) viewGroup.findViewById(R.id.my_recyclerview); TextView country_data = (TextView) viewGroup.findViewById(R.id.country_data); Typeface tp = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Mj_Text Bold.ttf"); adapterCardView = new AdapterCardView(getActivity(),arrayList); loadDatabase(); return viewGroup; } public void loadDatabase() { final Database database = new Database(getContext()); database.CreateDatabase(); database.openDatabase(); Cursor cursor=database.QueryData("SELECT * FROM Country WHERE Ghareh='آسیا'"); if (cursor != null) { if (cursor.moveToFirst()) { do { Structure structure = new Structure(); structure.setCountry_Name(cursor.getString(1)); structure.setCapital(cursor.getString(2)); structure.setGhareh(cursor.getString(3)); structure.setFlag(cursor.getString(4)); structure.setMeanCountry(cursor.getString(5)); arrayList.add(structure); } while (cursor.moveToNext()); recyclerView.addOnItemTouchListener( new RecyclerItemClickListener(getActivity(), recyclerView, new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { Alert alert = new Alert(getActivity()); for(int i=0;i<=position;i++) { alert.country_data.setText(arrayList.get(position).getCountry_Name()); alert.capital_data.setText(arrayList.get(position).getCapital()); alert.ghareh_data.setText(arrayList.get(position).getGhareh()); alert.meancountrydata.setText(arrayList.get(position).getMeanCountry()); int id=getContext().getResources().getIdentifier(arrayList.get(position).getFlag(),"mipmap",getContext().getPackageName()); alert.imgDialog.setImageResource(id); alert.show(); } } @Override public void onLongItemClick(View view, int position) { } })); } } LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext()); // adapterCardView=new AdapterCardView(getActivity(),arrayList); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.setAdapter(adapterCardView); database.close(); } }
  11. خیلی ممنون حالا توی کلاس Setting (که نور رو ذخیره می کنم) اون کدهایی که داخل try-catch هست و گفته بودید برای تغییر نور هست به "System" ایراد می گیره و ارور میده این کلاس ها رو هم ایمپورت می کنم ولی درست نمیشه: import java.io.IOException; import android.provider.Settings.System; (من مجبورم این قسمت ها رو کامنت کنم و بعد اجرا بگیرم) try { // To handle the auto Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); //Get the current system brightness brightness = System.getInt(cResolver, Settings.System.SCREEN_BRIGHTNESS); } catch (android.provider.Settings.SettingNotFoundException e) { //Throw an error case it couldn't be retrieved Log.e("Error", "Cannot access system brightness"); e.printStackTrace(); }
  12. اسم کلاسم Settings هست این کدها رو توی این کلاس نوشتم SharedPreferences.Editor editor= (SharedPreferences.Editor) getSharedPreferences("brightness",MODE_PRIVATE).edit(); editor.putInt("brightness",newValue); editor.commit();
  13. پس setting رو توی این دستور int brightness=Setting.getValue(); نمیشناسه چی کار باید بکنم؟