2016-08-19 11 views
0

Androidスタジオに私のCRMの詳細のリストを表示するコードがあります。これは非常にシンプルなフォーマットですが、動作させることはできません。基本的には次のとおりです。Androidのレイアウトが正常に機能しない

         Product Name 
Product Description 

次に、各製品のループスルーを行います。

ここdemo

がある:私も、私は、テンプレートとして使用していレイアウトXMLファイルの写真を持って

demo

この

は、次のように、それが現在に見えるものですコード私は今使用しています:

public class ShowPhotoshootList extends Activity { 

    private TextView tvData; 
    private Button Refresh; 
    private TextView btnText; 
    private ListView lvPhotoshoots; 
    /** 
    * ATTENTION: This was auto-generated to implement the App Indexing API. 
    * See https://g.co/AppIndexing/AndroidStudio for more information. 
    */ 
    private GoogleApiClient client; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_show_photoshoot_list); 

     lvPhotoshoots = (ListView) findViewById(R.id.lvPhotoshoots); 

     Refresh = (Button) findViewById(R.id.btnRefresh); 
     btnText = (TextView) findViewById(R.id.btnRefresh); 

     Refresh.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       new JsonTask().execute(CRMURL Not Shown for Privacy); 

      } 
     }); 

     // ATTENTION: This was auto-generated to implement the App Indexing API. 
     // See https://g.co/AppIndexing/AndroidStudio for more information. 
     client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); 
    } 

    public class JsonTask extends AsyncTask<String, String, List<Photoshoots>> { 

     @Override 
     protected void onPreExecute() { 
      Refresh.setEnabled(false); 
      btnText.setText("Loading"); 
     } 

     @Override 
     protected List<Photoshoots> doInBackground(String... params) { 
      HttpURLConnection connection = null; 
      BufferedReader reader = null; 

      try { 
       URL url = new URL(params[0]); 

       connection = (HttpURLConnection) url.openConnection(); 
       connection.connect(); 

       InputStream stream = connection.getInputStream(); 

       reader = new BufferedReader(new InputStreamReader(stream)); 

       StringBuffer buffer = new StringBuffer(); 

       String line = ""; 
       while ((line = reader.readLine()) != null) { 
        buffer.append(line); 
       } 

       String finalJson = buffer.toString(); 

       JSONObject parentObject = new JSONObject(finalJson); 

       JSONObject responseJSON = JSONUtils.jsonObjectFromJSONForKey(parentObject, "response"); 
       if (responseJSON != null) { 
        JSONObject resultJSON = JSONUtils.jsonObjectFromJSONForKey(responseJSON, "result"); 
        JSONObject contactsJSON = JSONUtils.jsonObjectFromJSONForKey(resultJSON, "Potentials"); 
        JSONArray parentArray = contactsJSON.getJSONArray("row"); 

        List<Photoshoots> photoshootsList = new ArrayList<>(); 
        for (int i = 0; i < parentArray.length(); i++) { 
         JSONObject mainObject = parentArray.getJSONObject(i); 
         JSONArray mainArray = mainObject.getJSONArray("FL"); 
         Photoshoots photoshootSchedule = new Photoshoots(); 

         for (int s = 1; s < mainArray.length(); s++) { 
          if (s == 1) { 
           JSONObject subObject = mainArray.getJSONObject(s); 
           Photoshoots PotentialName = new Photoshoots(); 
           String val = subObject.getString("val"); 
           String content = subObject.getString("content"); 
           PotentialName.setPotentialName(val + ": " + content + "\n"); 
           photoshootsList.add(PotentialName); 

          } else if (s == 2) { 
           JSONObject subObject = mainArray.getJSONObject(s); 
           Photoshoots Address = new Photoshoots(); 
           String val = subObject.getString("val"); 
           String content = subObject.getString("content"); 
           Address.setAddress(val + ": " + content + "\n"); 
           photoshootsList.add(Address); 

          } else if (s == 3) { 
           JSONObject subObject = mainArray.getJSONObject(s); 
           Photoshoots DateofShoot = new Photoshoots(); 
           String val = subObject.getString("val"); 
           String content = subObject.getString("content"); 
           DateofShoot.setDateofShoot(content); 
           photoshootsList.add(DateofShoot); 

          } 
          photoshootsList.add(photoshootSchedule); 

         } 

        } 

        return photoshootsList; 
       } 

      } catch (MalformedURLException e) { 
       e.printStackTrace(); 
      } catch (IOException e) { 
       e.printStackTrace(); 

      } catch (JSONException e) { 
       e.printStackTrace(); 
      } finally { 
       if (connection != null) { 
        connection.disconnect(); 
       } 
       try { 
        if (reader != null) { 
         reader.close(); 
        } 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
      } 

      return null; 

     } 

     @Override 
     protected void onPostExecute(List<Photoshoots> result) { 
      super.onPostExecute(result); 

      new CountDownTimer(60000, 1000) { 

       public void onTick(long millisUntilFinished) { 
        btnText.setText(millisUntilFinished/1000 + " Seconds"); 
       } 

       public void onFinish() { 
        btnText.setText("Refresh"); 
        Refresh.setEnabled(true); 
       } 
      }.start(); 

      PhotoshootAdapter adapter = new PhotoshootAdapter(getApplicationContext(), R.layout.row, result); 
      lvPhotoshoots.setAdapter(adapter); 
     } 
    } 

    public class PhotoshootAdapter extends ArrayAdapter { 

     private List<Photoshoots> photoshootsList; 
     private int resource; 
     private LayoutInflater inflater; 
     public PhotoshootAdapter(Context context, int resource, List<Photoshoots> objects) { 
      super(context, resource, objects); 
      photoshootsList = objects; 
      this.resource = resource; 
      inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); 
     } 

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

      if (convertView == null) { 

       convertView = inflater.inflate(resource, null); 
      } 

      TextView tvPotential; 
      TextView tvAddress; 

      tvPotential = (TextView) convertView.findViewById(R.id.tvPotential); 
      tvAddress = (TextView) convertView.findViewById(R.id.tvAddress); 

      tvPotential.setText(photoshootsList.get(position).getPotentialName()); 
      tvAddress.setText(photoshootsList.get(position).getAddress()); 

      return convertView; 
     } 
    } 

} 
` 

別のJavaクラスは、私はゲッター/セッターのために使用しているにもありますが、ここではそのためのコードは次のとおりです。

public class Photoshoots { 
    private String PotentialName; 
    private String Address; 
    private String DateofShoot; 

    public String getDateofShoot() { 
     return DateofShoot; 
    } 

    public void setDateofShoot(String dateofShoot) { 
     DateofShoot = dateofShoot; 
    } 

    public String getPotentialName() { 
     return PotentialName; 
    } 

    public void setPotentialName(String potentialName) {PotentialName = potentialName; 
    } 

    public String getAddress() { 
     return Address; 
    } 

    public void setAddress(String address) { 
     Address = address; 
    } 

} 
+0

リストビューア用のレイアウトファイルを投稿できますか? (R.layout.row) – Waves

答えて

0

わかりました。問題は解決しました。私はそれが自分の配列の各オブジェクトを設定し、最後に各配列と呼ばれるここで私は今

List<Photoshoots> photoshootsList = new ArrayList<>(); 
        for (int i = 0; i < parentArray.length(); i++) { 
         JSONObject mainObject = parentArray.getJSONObject(i); 
         JSONArray mainArray = mainObject.getJSONArray("FL"); 
         Photoshoots photoshoot = new Photoshoots(); 


        List<Photoshoots.potentialDetails> potentialDetails = new ArrayList<>(); 
        List<Photoshoots.addressDetails> addressDetails = new ArrayList<>(); 
        List<Photoshoots.dateDetails> dateDetails = new ArrayList<>(); 
        List<Photoshoots.PotentialIDDetails> PotentialID = new ArrayList<>(); 
         for (int s = 0; s < mainArray.length(); s++) { 
          if (s == 1) { 
           JSONObject subObject = mainArray.getJSONObject(s); 
           Photoshoots.potentialDetails PotentialName = new Photoshoots.potentialDetails(); 
           String val = subObject.getString("val"); 
           String content = subObject.getString("content"); 
           PotentialName.setPotentialName(content); 
           potentialDetails.add(PotentialName); 


          } else if (s == 2) { 
           JSONObject subObject = mainArray.getJSONObject(s); 
           Photoshoots.addressDetails Address = new Photoshoots.addressDetails(); 
           String val = subObject.getString("val"); 
           String content = subObject.getString("content"); 
           Address.setAddress(val + ": " + content); 
           addressDetails.add(Address); 

          } else if (s == 3) { 
           JSONObject subObject = mainArray.getJSONObject(s); 
           Photoshoots.dateDetails DateofShoot = new Photoshoots.dateDetails(); 
           String val = subObject.getString("val"); 
           String content = subObject.getString("content"); 
           DateofShoot.setDateofShoot(val + ": " + content); 
           dateDetails.add(DateofShoot); 


          }else if (s==0){ 
           JSONObject subObject = mainArray.getJSONObject(s); 
           Photoshoots.PotentialIDDetails PotentialIDAdd = new Photoshoots.PotentialIDDetails(); 
           String val = subObject.getString("val"); 
           String content = subObject.getString("content"); 
           PotentialIDAdd.setPotentialIDDetails(val + ": " + content); 
           PotentialID.add(PotentialIDAdd); 

          } 

を持っているコードは次のとおりです。

TextView tvPotential; 
     TextView tvAddress; 
     TextView tvDateofShoot; 




     tvPotential = (TextView) convertView.findViewById(R.id.tvPotential); 
     tvAddress = (TextView) convertView.findViewById(R.id.tvAddress); 
     tvDateofShoot = (TextView)convertView.findViewById(R.id.tvDateofShoot); 

     StringBuffer potentialBuffer = new StringBuffer(); 
     for(Photoshoots.potentialDetails details : photoshootsscheduleList.get(position).getPotentialDetails()){ 
      potentialBuffer.append(details.getPotentialName() + "\n"); 
      } 
     StringBuffer addressBuffer = new StringBuffer(); 
     for(Photoshoots.addressDetails details : photoshootsscheduleList.get(position).getAddressDetails()){ 
      addressBuffer.append(details.getAddress() + "\n"); 
     } 
     StringBuffer dateBuffer = new StringBuffer(); 
     for(Photoshoots.dateDetails details : photoshootsscheduleList.get(position).getDateDetails()){ 
      dateBuffer.append(details.getDateofShoot()); 
     } 
     final StringBuffer potentialIDBuffer = new StringBuffer(); 
     for(Photoshoots.PotentialIDDetails details : photoshootsscheduleList.get(position).getPotentialIDDetails()){ 
      potentialIDBuffer.append(details.getPotentialIDDetails()); 
     } 


     tvPotential.setText(potentialBuffer.toString()); 
     tvAddress.setText(addressBuffer.toString()); 
     tvDateofShoot.setText(dateBuffer.toString()); 

これは私が持っていた問題を修正するために管理し、それらはすべて正常に動作します。

0

は、あなたの大型のTextView(tvPotential)へandroid:gravity="center"属性を追加します。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="4dp" 
    android:orientation="vertical"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:id="@+id/tvPotential" 
     android:layout_gravity="center_horizontal" 

     <!-- Here --> 
     android:gravity="center"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:text="Medium Text" 
     android:id="@+id/tvAddress" /> 
</LinearLayout> 
+0

それは何もしなかった、まったく同じように見える。 –

+0

@UnlikelyLegendsMedia最初のスクリーンショットの灰色のバーは「製品名」のすべての部分ですか? – Waves

+0

はい、個人情報が含まれているためぼかしされていますが、正しい情報が表示されています。 –

関連する問題