amulyakhare/TextDrawable

Display in SimpleAdapter in Fragment

Opened this issue · 0 comments

I have a data coming from Remote database (MySQL), which i set to the SimpleAdapter and then this adapter to ListView.
How do i set TextDrawable to the SimpleAdapter

Below is my HomeFragment which includes everything:

` @OverRide
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_home, container, false);

   mainListView = (ListView) rootView.findViewById(R.id.newsListView);


    //Circular image
    TextDrawable drawable1 = TextDrawable.builder().beginConfig().
            withBorder(4).textColor(Color.RED).useFont(Typeface.DEFAULT).fontSize(30).bold().toUpperCase()
            .endConfig().buildRoundRect("A", Color.GREEN, 10);

    ColorGenerator generator = ColorGenerator.MATERIAL;
    int color1 = generator.getRandomColor();

    TextDrawable.IBuilder builder = TextDrawable.builder().beginConfig().withBorder(4).endConfig().rect();
    TextDrawable ic1 = builder.build("A", color1);

    View justAview = inflater.inflate(R.layout.list_homefragment, container, false);
    image = (ImageView)justAview.findViewById(R.id.image_view);
    image.setImageDrawable(drawable1);

    //End


    new getHomeFragmentList().execute();



    String up = "▲";
    String down = "▼";



    //Getting Data From ListView on onClick
    mainListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


           // String text = mainListView.getItemAtPosition(position).toString();

            TextView pname = (TextView) view.findViewById(R.id.FNAME);
            String pName = pname.getText().toString();

            /*TextView pid = (TextView) view.findViewById(android.R.id.text2);
            String pID = pid.getText().toString();*/

            //Toast.makeText(getActivity(), "Name:" + pName + "\n ID:" + pID, Toast.LENGTH_SHORT).show();

            //Sending Data To DetailViewFragment
            DetailViewFragment DVF = new DetailViewFragment();
            Bundle something = new Bundle();
            something.putString("key", pName); //takes <Key, Value> pair
            DVF.setArguments(something);
            //Now Commit Transaction
            getFragmentManager().beginTransaction().replace(R.id.fragment_container, DVF).addToBackStack(null).commit();
            //END


        }
    });
    // END
    return rootView;


}


private class getHomeFragmentList extends AsyncTask<Void, Void, String>
{
    ProgressDialog pDialog;

    @Override
    protected void onPreExecute() {
        pDialog = ProgressDialog.show(HomeFragment.this.getActivity(), "Please Wait...", "" , false, false);
    }

    @Override
    protected String doInBackground(Void... params) {
        RequestHandler rh = new RequestHandler();

        String data = rh.sendGetRequest(Configuration.URL_GET_HOMEFragmentList);
        Log.d("Received Data", ":" + data);
        if(data !=null)
        {

            JSONArray jsonArray = null;
            try {
                jsonArray = new JSONArray(data);

                for (int i=0; i<jsonArray.length();i++)
                {
                    JSONObject jo = jsonArray.getJSONObject(i);

                    String pid = jo.getString(pID);
                    String fname = jo.getString(fNAME);
                    String lname = jo.getString(lNAME);
                    String brreading = jo.getString(BRREADING);
                    String bsrdate = jo.getString(BSRDATE);
                    String bsrtime = jo.getString(BSRTIME);



                    HashMap<String, String> hashMap = new HashMap<>();
                    hashMap.put()
                    hashMap.put(fNAME, fname);
                    hashMap.put(lNAME, lname);
                    hashMap.put(BRREADING, brreading);
                    hashMap.put(BSRDATE, bsrdate);
                    hashMap.put(BSRTIME, bsrtime);




                    homepatientList.add(hashMap);
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }

        }else
        {
            Log.v("", "No Data from URL");
        }


        return null;
    }


    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        pDialog.dismiss();

        mainlistAdapter = new SimpleAdapter(getActivity(), homepatientList, R.layout.list_homefragment,
        new String[] {fNAME,lNAME,BRREADING, BSRDATE, BSRTIME}, new int[]{R.id.FNAME, R.id.LNAME, R.id.READING, R.id.DATE, R.id.TIME});
        mainListView.setAdapter(mainlistAdapter);
    }
}`