免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
如何在Android中為網(wǎng)格視圖設(shè)置行?

現(xiàn)在我正在將數(shù)據(jù)從XML文件顯示到android的網(wǎng)格視圖中.這是xml的確切文件鏈接

http://54.251.60.177/StudentWebService/StudentDetail.asmx/GetTMSOrders”其中
我正在嘗試顯示.我已經(jīng)成功地完成了這個概念,但是這里的問題是,我沒有得到下圖所示的答案

我需要在Android中顯示如下圖所示

但是我只得到下面的圖像…..

如何克服這個概念?有人可以讓我說清楚嗎?

感謝您的寶貴時間!..

這里我的參考資料,請找到

GridviewSample.java

public class GridviewSample extends Activity {// All static variablesstatic final String URL = "http://54.251.60.177/StudentWebService/StudentDetail.asmx/GetTMSOrders";// XML node keysstatic final String KEY_TABLE = "Table"; // parent nodestatic final String KEY_CUST = "Cust_Name";static final String KEY_ORDER = "Order_No";static final String KEY_FREIGHT = "Freight_Rate";static final String KEY_STATION1 = "Station_Name";static final String KEY_STATION2 = "Station_Name1";@Overridepublic void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.main);    GridView gv =  (GridView)findViewById(R.id.gridView1);    ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();    XMLParser parser = new XMLParser();    String xml = parser.getXmlFromUrl(URL); // getting XML    Document doc = parser.getDomElement(xml); // getting DOM element    NodeList nl = doc.getElementsByTagName(KEY_TABLE);    // looping through all item nodes <item>    for (int i = 0; i < nl.getLength(); i  )     {        // creating new HashMap        HashMap<String, String> map = new HashMap<String, String>();        Element e = (Element) nl.item(i);        // adding each child node to HashMap key => value        map.put(KEY_CUST, parser.getValue(e, KEY_CUST));        map.put(KEY_ORDER, parser.getValue(e, KEY_ORDER));        map.put(KEY_FREIGHT, parser.getValue(e, KEY_FREIGHT));        map.put(KEY_STATION1, parser.getValue(e, KEY_STATION1));        map.put(KEY_STATION2, parser.getValue(e, KEY_STATION2));        // adding HashList to ArrayList        menuItems.add(map);    }    // Adding menuItems to ListView SimpleAdapter adapter = new SimpleAdapter(this, menuItems,R.layout.grid_item, new String[] { KEY_CUST, KEY_ORDER, KEY_FREIGHT,KEY_STATION1,KEY_STATION2 }, new int[]  {    R.id.cust, R.id.order, R.id.freight,R.id.statio1,R.id.station2 });    gv.setAdapter(adapter);    gv.setOnItemClickListener(new OnItemClickListener()     {    public void onItemClick(AdapterView<?> Table, View v,int position, long id)     {    String cust = ((TextView) v.findViewById(R.id.cust)).getText().toString();    String order = ((TextView) v.findViewById(R.id.order)).getText().toString();    String freight = ((TextView) v.findViewById(R.id.freight)).getText().toString();    String station1 = ((TextView) v.findViewById(R.id.statio1)).getText().toString();    String station2 = ((TextView) v.findViewById(R.id.station2)).getText().toString();    // Starting new intent    Intent in = new Intent(getApplicationContext(), Single_gridview_item.class);      in.putExtra(KEY_CUST, cust);      in.putExtra(KEY_ORDER, order);      in.putExtra(KEY_FREIGHT, freight);      in.putExtra(KEY_STATION1, station1);      in.putExtra(KEY_STATION2, station2);      startActivity(in);      }    }); }   }

Single_gridview_item

public class Single_gridview_item  extends Activity{// XML node keysstatic final String KEY_TABLE = "Table"; // parent nodestatic final String KEY_CUST_NAME = "Cust_Name";static final String KEY_ORDER = "Order_No";static final String KEY_FREIGHT = "Freight_Rate";static final String KEY_STATION1 = "Station_Name";static final String KEY_STATION2="Station_Name1";@Overridepublic void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.single_grid_item);    // getting intent data    Intent in = getIntent();    // Get XML values from previous intent    String cust = in.getStringExtra(KEY_CUST_NAME);    String order = in.getStringExtra(KEY_ORDER);    String freight = in.getStringExtra(KEY_FREIGHT);    String station1 = in.getStringExtra(KEY_STATION1);    String station2 = in.getStringExtra(KEY_STATION2);    // Displaying all values on the screen    TextView lblcust = (TextView) findViewById(R.id.cust_label);    TextView lblorder = (TextView) findViewById(R.id.order_label);    TextView lblfreight = (TextView) findViewById(R.id.freight_label);    TextView lblstation1 = (TextView) findViewById(R.id.station1_label);    TextView lblstation2 = (TextView) findViewById(R.id.station2_label);    lblcust.setText(cust);    lblorder.setText(order);    lblfreight.setText(freight);    lblstation1.setText(station1);    lblstation2.setText(station2);}}

XMLParser.java

public class XMLParser {// constructorpublic XMLParser() {}/** * Getting XML from URL making HTTP request * @param url string * */public String getXmlFromUrl(String url) {    String xml = null;    try {        // defaultHttpClient        DefaultHttpClient httpClient = new DefaultHttpClient();        HttpPost httpPost = new HttpPost(url);        HttpResponse httpResponse = httpClient.execute(httpPost);        HttpEntity httpEntity = httpResponse.getEntity();        xml = EntityUtils.toString(httpEntity);    } catch (UnsupportedEncodingException e) {        e.printStackTrace();    } catch (ClientProtocolException e) {        e.printStackTrace();    } catch (IOException e) {        e.printStackTrace();    }    // return XML    return xml;}/** * Getting XML DOM element * @param XML string * */public Document getDomElement(String xml){    Document doc = null;    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();    try {        DocumentBuilder db = dbf.newDocumentBuilder();        InputSource is = new InputSource();            is.setCharacterStream(new StringReader(xml));            doc = db.parse(is);         } catch (ParserConfigurationException e) {            Log.e("Error: ", e.getMessage());            return null;        } catch (SAXException e) {            Log.e("Error: ", e.getMessage());            return null;        } catch (IOException e) {            Log.e("Error: ", e.getMessage());            return null;        }        return doc;}/** Getting node value  * @param elem element  */ public final String getElementValue( Node elem ) {     Node child;     if( elem != null){         if (elem.hasChildNodes()){             for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() ){                 if( child.getNodeType() == Node.TEXT_NODE  ){                     return child.getNodeValue();                 }             }         }     }     return ""; } /**  * Getting node value  * @param Element node  * @param key string  * */ public String getValue(Element item, String str) {             NodeList n = item.getElementsByTagName(str);                return this.getElementValue(n.item(0));    }}

解決方法:

不要使用網(wǎng)格視圖,它不會幫助您.它旨在將項目列表顯示為網(wǎng)格.您可以指定列數(shù),但是顯示表對于TableLayout來說是更多的工作.

來源:https://www.icode9.com/content-4-496501.html
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Android開發(fā)筆記(六)— 使用Drawable類、Color類和Resource類更改顏色
Android中的SharedPreferences存儲數(shù)據(jù)方式
單選按鈕 RadioButton 的應(yīng)用
android的Intent返回值
在String.xml中設(shè)置部分字體的顏色
加法計算器
更多類似文章 >>
生活服務(wù)
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服