Androidスタジオに私のCRMの詳細のリストを表示するコードがあります。これは非常にシンプルなフォーマットですが、動作させることはできません。基本的には次のとおりです。Androidのレイアウトが正常に機能しない
Product Name
Product Description
次に、各製品のループスルーを行います。
がある:私も、私は、テンプレートとして使用していレイアウトXMLファイルの写真を持って
:
この
は、次のように、それが現在に見えるものですコード私は今使用しています: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;
}
}
リストビューア用のレイアウトファイルを投稿できますか? (R.layout.row) – Waves