2016-05-21 3 views
0

У меня проблема с изображениями diplayin, ничего не отображается в sceen, кажется пустым только данные не отображаются без изображений. Я думаю, что проблема при анализе данных JSON в картинках. здесь, в Фрагменте отеля, где я хочу отобразить фотогалерею.отображение изображения с использованием библиотеки JSON и Coverflow

public class ViewHotels extends AppCompatActivity { 
    private Bitmap bitmap; 
    private TextView nom1; 
    private TextView grade; 
    private TextView tele; 
    private ImageView image; 
    private TextView sit; 
    private TextView add1; 
    private TextView email1; 
    private FloatingActionButton fab; 
    LinearLayout layout; 
    private String id; 
    public static final String URL="http://gabes.comlu.com/Base_Controle/getEmpdetail.php"; 
    private FeatureCoverFlow coverFlow; 
    private CoverFlowAdapter adapter; 
    private ArrayList<Game> games; 
    String image2; 
    String addresses; 
    String subject; 
    public static final String TAG_JSON_ARRAY="result"; 

    ImageView im; 
    private int imageSource; 


    public String stringUrl; 
    public String stringUrl1; 
    public String stringUrl2; 
    public String stringUrl3; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.hotelsdetails); 
     final Intent intent = getIntent(); 
     layout=(LinearLayout) findViewById(R.id.layout); 
     coverFlow = (FeatureCoverFlow) findViewById(R.id.coverflow); 

     settingDummyData(); 
     adapter = new CoverFlowAdapter(this, games); 
     coverFlow.setAdapter(adapter); 
     coverFlow.setOnScrollPositionListener(onScrollListener()); 

     id = intent.getStringExtra("Type"); 
     nom1 = (TextView) findViewById(R.id. nom); 
     grade = (TextView) findViewById(R.id. grade); 
     tele = (TextView) findViewById(R.id. tele); 
     image= (ImageView)findViewById(R.id.imageView); 
     sit=(TextView) findViewById(R.id.site); 
     add1=(TextView) findViewById(R.id.adde); 
     email1=(TextView)findViewById(R.id.email); 


     nom1.setText(id); 
     im =new ImageView (this); 
     getEmployee(); 
    } 


    private void getEmployee(){ 
     final String login11 = nom1.getText().toString().trim(); 
     class GetEmployee extends AsyncTask<Void,Void,String>{ 
      ProgressDialog loading; 
      @Override 
      protected void onPreExecute() { 
       super.onPreExecute(); 
       loading = ProgressDialog.show(ViewHotels.this,"Fetching...","Wait...",false,false); 
      } 

      @Override 
      protected void onPostExecute(String s) { 
       super.onPostExecute(s); 
       loading.dismiss(); 
       showEmployee(s); 
      } 

      @Override 
      protected String doInBackground(Void... v) { 
       HashMap<String,String> params = new HashMap<>(); 
       params.put("id",login11) 

       RequestHandler rh = new RequestHandler(); 

       String res= rh.sendPostRequest(URL, params); 

       return res; 
      } 
     } 
     GetEmployee ge = new GetEmployee(); 
     ge.execute(); 
    } 
    private void showEmployee(String json){ 
     try { 

      JSONArray result = new JSONArray(json); 
      JSONObject c = result.getJSONObject(0); 
      String name = c.getString("nom"); 
      String tel = c.getString("tele"); 
      String grade1 = c.getString("grade"); 
      String image1 = c.getString("image"); 
      image2 = c.getString("img1"); 
      String image3 = c.getString("img2"); 
      String image4 = c.getString("img3"); 
      String site= c.getString("site"); 
      String add11= c.getString("add"); 
      String email11= c.getString("email"); 

      tele.setText("Tel : \t"+tel); 
      grade.setText("Grade : \t"+grade1); 
      sit.setText("site: \t"+site); 
      add1.setText("adresse :\t" + add11); 
      email1.setText("email :\t"+ email11); 


      final ImageView im1 =new ImageView (this); 
      final ImageView im2 =new ImageView (this); 
      final ImageView im3 =new ImageView (this); 

      stringUrl = ("http://gabes.comlu.com/Base_Controle/ImageBD/"+image1+".jpg"); 
      stringUrl1 = ("http://gabes.comlu.com/Base_Controle/ImageBD/"+image2+".jpg"); 
      stringUrl2 = ("http://gabes.comlu.com/Base_Controle/ImageBD/"+image3+".jpg"); 
      stringUrl3 = ("http://gabes.comlu.com/Base_Controle/ImageBD/"+image4+".jpg"); 

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

     } 

    private FeatureCoverFlow.OnScrollPositionListener onScrollListener() { 
     return new FeatureCoverFlow.OnScrollPositionListener() { 
      @Override 
      public void onScrolledToPosition(int position) { 
       Log.v("ViewHotels", "position: " + position); 
      } 

      @Override 
      public void onScrolling() { 
       Log.i("ViewHotels", "scrolling"); 
      } 
     }; 
    } 
    private void settingDummyData() { 
     games = new ArrayList<>(); 
     Game game1 = new Game("stringUrl",""); 
     Game game2 = new Game("stringUrl1",""); 
     Game game3 = new Game("stringUrl2",""); 

     games.add(game1); 
     games.add(game2); 
     games.add(game3); 


    } 
} 

Вот Coverflow адаптер:

public class CoverFlowAdapter extends BaseAdapter { 

private ArrayList<Game> data; 
private AppCompatActivity activity; 

public CoverFlowAdapter(AppCompatActivity context, ArrayList<Game> objects) { 
    this.activity = context; 
    this.data = objects; 
} 
@Override 
public int getCount() { 
    return data.size(); 
} 

@Override 
public Game getItem(int position) { 
    return data.get(position); 
} 

@Override 
public long getItemId(int position) { 
    return position; 
} 

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

    ViewHolder viewHolder; 

    if (convertView == null) { 
     LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = inflater.inflate(R.layout.item_flow_view, null, false); 

     viewHolder = new ViewHolder(convertView); 
     convertView.setTag(viewHolder); 
    } else { 
     viewHolder = (ViewHolder) convertView.getTag(); 
    } 
    try { 
     URL myFileUrl = new URL(data.get(position).getImageSource()); 
     Log.e("TAG stringUri",myFileUrl+""); 
     HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection(); 
     conn.setDoInput(true); 
     conn.connect(); 
     InputStream is = conn.getInputStream(); 
     viewHolder.gameImage.setImageBitmap(BitmapFactory.decodeStream(is)); 
    } 
    catch (MalformedURLException e) { 
     e.printStackTrace(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    //viewHolder.gameImage.setImageResource(data.get(position).getImageSource()); 
    viewHolder.gameName.setText(data.get(position).getName()); 
    return convertView; 
} 

private static class ViewHolder { 
    private TextView gameName; 
    private ImageView gameImage; 

    public ViewHolder(View v) { 
     gameImage = (ImageView) v.findViewById(R.id.image); 
     gameName = (TextView) v.findViewById(R.id.name); 
    } 
} 

} И это Игра класс:

public class Game { 

private String name; 
private String imageSource; 

public Game (String imageSource, String name) { 
    this.name = name; 
    this.imageSource = imageSource; 
} 

public String getName() { 
    return name; 
} 

public String getImageSource() { 
    return imageSource; 
} 

}

ответ

0

Я думаю, что (один из) ваша проблема (s) находится в этом разделе:

Game game1 = new Game("stringUrl",""); 
Game game2 = new Game("stringUrl1",""); 
Game game3 = new Game("stringUrl2",""); 

Вы передаете строку «stringUrlx» вашему игровому конструктору. В Java кавычки ("") используются для явного определения строки, что означает, что вы передаете «stringUrl» вместо переменной stringUrl, которая будет иметь правильный контент («« + image1 + ». JPG ").

поэтому замените, например.

Game game1 = new Game("stringUrl",""); 

по

Game game1 = new Game(stringUrl,""); 

Это должно решить, что один вопрос.

Кроме этого, вы также столкнетесь с проблемами при загрузке файлов и управлении памятью. Я советую вам изучить java-специальные учебные пособия, в которых используются предварительно построенные библиотеки загрузки и кеширования изображений (такие как Glide или Picasso!)

+0

https://plus.google.com/u/0/+MarwaMarwita967/posts/Z2UwFfMsX1e? Pid = 6287456633495237122 & oid = 110504829645267340465 –

+0

Кажется, у вас есть * правильно * применил мое предложенное изменение только к первому stringUrl. Там вы можете видеть, что теперь он говорит «... null.jpg» Это означает, что String image1 = c.getString («образ»); нулевой. Итак ... попытайтесь выяснить, что может это сделать! – Aeefire

+0

Да! Я изменил URL-адрес, как вы предложили. –

 Смежные вопросы

  • Нет связанных вопросов^_^