小编Luk*_*ley的帖子

Android将Json对象添加到Array中

我要做的是创建一个JSONObject,其中包含一个由String组织的其他JSONObject数组?例如,我想创建一个JSONObject,其中包含一个对象数组,这些对象包含也按匹配日期组织的灯具

为您提供我想要实现的目标的视觉参考

JSONObject (JSONArray("Object 10/10/12" {(fixtures content)(fixtures content)}")
                     ("Object 11/10/12" {(fixtures content)(fixtures content)}"))
Run Code Online (Sandbox Code Playgroud)

继续我到目前为止所尝试的但是却无法让它发挥作用

        String matchDate1 = null;
        JSONArray datesArray = null;
        JSONObject fixturesInfo = null;
        JSONArray fixturesInfoArray = null;
        String matchDateTemp = null;

        for(int f = 0; f < fixturesArray.length(); f++){

            JSONObject matchDateDict = fixturesArray.getJSONObject(f);
            matchDate1 = matchDateDict.getString("matchdate");
            JSONArray fixturesInfoDict = fixturesInfo.getJSONArray(matchDate1);

           if(fixturesInfoDict == null){
               tempArray = null;
           } else {
               tempArray = fixturesInfoDict;
           }

           if(matchDateTemp != matchDate1){
              fixturesInfoArray.put(matchDate1);
           }

          matchDateTemp = matchDate1;

          tempArray.put(fixturesArray.getJSONObject(f));
          fixturesInfo.put(matchDate1, tempArray);

        }




            Log.v("MyFix", "fixturesInfo …
Run Code Online (Sandbox Code Playgroud)

android json

2
推荐指数
1
解决办法
2万
查看次数

Android AdMob错误在调用load之前,必须设置广告尺寸和广告单元ID

嗨,我正在尝试将广告添加到我的应用程序中,但我一直收到错误

The ad size and ad unit ID must be set before load is called.
Run Code Online (Sandbox Code Playgroud)

继续我到目前为止所尝试的内容

继承我的布局(我有我在我的应用程序中放入xml的实际adUnitId号码,但是没有把它放在这里,因为我认为在线发布它不是一个好主意)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/levelView" 
     >

     <RelativeLayout 
      android:id="@+id/header" 
      android:layout_width="match_parent"
      android:layout_height="70dp"
      >


          <TextView
            android:id="@+id/tv1"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
           android:layout_marginTop="5dp"
            android:textSize="15dp"
            android:textColor="@color/white"
            android:text="hello"
            android:gravity="center"
            android:singleLine="true"/>

         <TextView
            android:id="@+id/headertitle"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
             android:layout_below="@+id/headertitle"
           android:textSize="40dp"
            android:textColor="@color/white"
            android:layout_marginTop="15dp"
            android:text="2014"
            android:gravity="center"
            android:singleLine="true"/>

         <ImageView
             android:id="@+id/imageView1"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_centerVertical="true"
             android:layout_marginLeft="18dp"
             android:layout_toRightOf="@+id/headertitle"
             android:src="@drawable/level_logo" />

    </RelativeLayout>


   <GridView
        android:id="@+id/gridView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/header"
        android:numColumns="4"
        android:listSelector="@null"
        android:layout_centerHorizontal="true" >
    </GridView>



  <com.google.android.gms.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         android:layout_below="@+id/gridView1"
                         ads:adUnitId="MY ID …
Run Code Online (Sandbox Code Playgroud)

android admob

2
推荐指数
1
解决办法
5381
查看次数

Android将月份作为两位数字

嗨有谁知道如何将月份作为两位数的数字,例如04或05?

android date

1
推荐指数
1
解决办法
7333
查看次数

Android创建JSON对象的JSON数组

嗨有没有人知道如何创建一个包含每个对象包含多个对象的对象的数组?我似乎无法理解它

结构应该是这样的

Array{[object]{subobject,subobject}
      [object]{subobject,subobject}
     }
Run Code Online (Sandbox Code Playgroud)

继承人到目前为止我所拥有的

JSONObject obj = new JSONObject(json2);    
            JSONObject objData = obj.getJSONObject("data");
            fixturesArray = objData.getJSONArray("fixtures");

            JSONArray FixArray = new JSONArray();


            for(int t = 0; t < fixturesArray.length(); t++){
            JSONObject fixObj = fixturesArray.getJSONObject(t);
            String Matchdate = fixObj.getString("matchdate");
            JSONObject DateObj = DateObj.put(Matchdate, DateObj);
Run Code Online (Sandbox Code Playgroud)

继承我的JSON本质上是我所拥有的如果是一个固定装置的饲料我需要将它们订购到日期数组中

{
    "code":200,
    "error":null,
    "data":{
        "fixtures":[
            {
                "kickoff":"15:00:00",
                "matchdate":"2012-07-28",
                "homescore":null,
                "awayscore":null,
                "attendance":null,
                "homepens":null,
                "awaypens":null,
                "division_id":"5059",
                "division":"Testing 1",
                "comp":"LGE",
                "location":null,
                "fixture_note":null,
                "hometeam_id":"64930",
                "hometeam":"Team 1",
                "awayteam_id":"64931",
                "awayteam":"Team 2"
            }, {
                "kickoff":"15:00:00",
                "matchdate":"2012-07-28",
                "homescore":null,
                "awayscore":null,
                "attendance":null,
                "homepens":null,
                "awaypens":null,
                "division_id":"5059", …
Run Code Online (Sandbox Code Playgroud)

android json

1
推荐指数
1
解决办法
1万
查看次数

用JSONArray中的空字符串替换所有空值

嗨,我有一个JSONObject,我已经转换为JSON数组,我想知道如何遍历整个数组找到任何null的实例,并用""替换它?

继续我到目前为止,但不知道从哪里开始

JSONObject fullNetworkfile = fullNetworkDataFromFile;
     JSONArray fullNetworkArray = new JSONArray();
     fullNetworkArray.put(fullNetworkfile);
Run Code Online (Sandbox Code Playgroud)

java android

1
推荐指数
1
解决办法
1639
查看次数

Android从String Array中设置listItem背景颜色

有谁知道如何以编程方式从字符串数组中设置列表项的背景?我有两个字符串数组,一个是文本视图的标题,另一个是颜色引用.我已将标题数组添加到数组适配器并显示但现在我想更改数组中每个项目的背景颜色

继承我的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="50dp"
      >

    <TextView
        android:id="@android:id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="18dp"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:gravity="center" />

</RelativeLayout> 
Run Code Online (Sandbox Code Playgroud)

到目前为止我的代码

     ListView menuList = (ListView) findViewById(R.id.listView1);
        String[] items = {"menuItem1","menuItem2","menuItem3","menuItem4","menuItem4","menuItem5","menuItem6","menuItem7","menuItem8"};  
  String[] colors = {"#ffffff","#000000","#ffffBB","#ffffDD","#ff654d","#ffffff","#ffffff","#ffffff","#ffffff"};   
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.drawer_list_item, android.R.id.text1, items);
        menuList.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

android

1
推荐指数
1
解决办法
3032
查看次数

在充气另一个视图后Android更改textView

嗨,我正在尝试在膨胀的视图中更改textview但应用程序崩溃.

我想要做的是用变量HomeTeam和AwayTeam中的内容填充文本视图这些变量不为null,因为当我记录它们时,那​​里有名字.

所以我的问题是如何更改文本视图并替换其内容

这是我尝试过的

for(int t = 0; t < 1; t++){

               resultsDict = jArray.getJSONObject(t);
              String HomeTeam = resultsDict.getString("hometeam");
              String AwayTeam = resultsDict.getString("awayteam");

              Log.v("lc","hometeam" + HomeTeam);
              Log.v("lc","awayteam" + AwayTeam);


           }


           resultsView = LayoutInflater.from(getBaseContext()).inflate(R.layout.resultscell,
                     null);

           TextView homeTeam = (TextView) findViewById(R.id.HomeTeam);
           homeTeam.setText(HomeTeam);
Run Code Online (Sandbox Code Playgroud)

膨胀的观点

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:padding="20dp" >

    <TextView
        android:id="@+id/TextView04"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="-"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/blue" 
        android:textStyle="bold"
      />

    <TextView
        android:id="@+id/HomeScore"
        android:layout_width="20dp"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/TextView04"
        android:text="0"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/blue" 
        android:textStyle="bold"
        />

    <TextView
        android:id="@+id/AwayScore"
        android:layout_width="20dp"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/TextView04"
        android:text="0" …
Run Code Online (Sandbox Code Playgroud)

android textview layout-inflater

0
推荐指数
1
解决办法
3765
查看次数

Android只运行一次runnable

嗨我有一个动画,我想延迟一个runnable的开始,但它导致动画循环,我不需要我只是想让它延迟然后运行一次有谁知道如何?

继承我的代码

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_initialsetup);
        handler = new Handler();
        final Runnable r = new Runnable()
        {
            public void run() 
            {
                animations();
                handler.postDelayed(this, 1000);
            }
        };
        handler.postDelayed(r, 1000);
    }


    public void animations(){
        image = (ImageView)findViewById(R.id.su_shirts);
        AnimationMovepos = AnimationUtils.loadAnimation(this, R.anim.shirt_anim);   
        image.startAnimation(AnimationMovepos); 
    }
}
Run Code Online (Sandbox Code Playgroud)

android runnable

0
推荐指数
1
解决办法
5797
查看次数

android清除字符串生成器

可能的重复:
如何清除/清空 Java Stringbuilder

我正在向字符串添加值,然后在文本视图中显示它,但是当我刷新页面时,它不会先清除字符串。
它只是不断地添加它。

有没有办法清除android中的字符串生成器?

到目前为止我尝试过的

StringBuilder sb = new StringBuilder();
sb.delete(0,sb.length());
for (String s : awayScores)
{
    sb.append(s);
    sb.append("\n");
}

StringBuilder sb2 = new StringBuilder();
sb2.delete(0,sb2.length());
for (String h : homeScores)
{
    sb2.append(h);
    sb2.append("\n");
}

 String awayeve = sb.toString();
 String homeeve = sb2.toString();

Log.v("home", "homeeve" + homeeve);
Log.v("home", "awayeve" + awayeve);
Run Code Online (Sandbox Code Playgroud)

java stringbuilder android

0
推荐指数
1
解决办法
3274
查看次数