On Tuesday, December 1, 2015 at 2:48:53 AM UTC+5:30, AbdulMajeed Mohammad 
wrote:
>
> Hi,
>
> I have json file in my localhost and I want to load it in ListView with 
> custom adapter by retrofit 2.0 , but nothing show up 
>
> and I don't know if the problem from an adapter or the json file or 
> retrofit call, here the classes 
>
> MainActivity.java
>
> public class MainActivity extends AppCompatActivity {
>
>
>      ListView listView;
>
>
>     @Override
>     protected void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.activity_main);
>
>         listView = (ListView) findViewById(R.id.listView);
>
>
>          final ArrayList<tel_list> data = new ArrayList<tel_list>();
>
>
>         Retrofit retrofit = new 
> Retrofit.Builder().baseUrl("http://10.0.2.2";).addConverterFactory(GsonConverterFactory.create()).build();
>
>         TelService service = retrofit.create(TelService.class);
>         retrofit.Call<List<tel_list>> calls = service.getphones("telephones");
>         calls.enqueue(new Callback<List<tel_list>>() {
>             @Override
>             public void onResponse(Response<List<tel_list>> response, 
> Retrofit retrofit) {
>
>
>                 TelAdapter adapter = new  TelAdapter (MainActivity.this, 
> R.layout.list_item, data);
>                 listView.setAdapter(adapter);
>
>             }
>
>             @Override
>             public void onFailure(Throwable t) {
>
>             }
>         });
>
>
>     }
>     }
>
>
> TelAdapter.java
>
> public class TelAdapter extends ArrayAdapter<tel_list> {
>
>     static Context context;
>     static int layoutResourceId;
>     private List<tel_list> data = null;
>
>
>     public TelAdapter(Context context,int layoutResourceId, List<tel_list> 
> data) {
>         super(context, layoutResourceId, data);
>         this.layoutResourceId = layoutResourceId;
>         this.context = context;
>         this.data = data;
>
>     }
>
>
>
>     public long getItemId(int position) {
>         return position;
>     }
>
>     @Override
>     public View getView(int position, View convertView, ViewGroup parent) {
>         View row = convertView;
>         TelHolder holder;
>
>         if (row == null) {
>             LayoutInflater inflater = ((Activity) 
> context).getLayoutInflater();
>             row = inflater.inflate(layoutResourceId, parent, false);
>
>             holder = new TelHolder();
>
>             holder.names = (TextView) row.findViewById(R.id.names);
>             holder.numbers = (TextView) row.findViewById(R.id.numbers);
>
>             row.setTag(holder);
>         } else {
>             holder = (TelHolder) row.getTag();
>         }
>
>         tel_list telephnoes = data.get(position);
>         holder.names.setText(telephnoes.getName());
>         holder.numbers.setText(telephnoes.getName());
>         return row;
>
>     }
>
>     static class TelHolder {
>         TextView names;
>         TextView numbers;
>
>     }
> }
>
>
> tel_list.java
>
> public class tel_list {
>
>     private String name;
>     private String number;
>
>     public String getName() {
>         return name;
>     }
>
>     public void setName(String name) {
>         this.name = name;
>     }
>
>     public String getNumber() {
>         return number;
>     }
>
>     public void setNumber(String number) {
>         this.number = number;
>     }
> }
>
>
>
> TelService.java
>
>
> public interface TelService {
>     @GET("/alruthea/{getphones}.php")
>     retrofit.Call<List<tel_list>> getphones(@Path("getphones")String 
> telephones);
>
>
> }
>
>
>
>
> in addition I couldn't add the file name extensions inside @Path
>
>
> please help,
>



Try to print your data using LOG function and try to narrow down problem. 
If your LOG does not print anything it means you are not getting any data 
likewise do this to check functionality that you have implemented and 
figure out where is problem in the code! happy coding !
 

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/80af1f4e-6487-43ab-99ff-2de850bf4078%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to