小编Sim*_*mon的帖子

issue:指定的子级已有父级.您必须首先在孩子的父母上调用removeView()

我开发应用程序以将动态数据添加到多个表视图.结构如下.

在此输入图像描述 我在onPostExecute中的代码是:

    protected void onPostExecute(List<String> results){
int ind,i = 0;
ScrollView sv=null;
TableLayout tl=null;
TableRow tr = null;
int mjsonlength=results.size();
if(results!=null){

 TableLayout indextl=(TableLayout)findViewById(R.id.indextablelayout);
    TableRow indextr=new TableRow(SubProducts.this);
    //indext1.moveToFirst();
    LinearLayout llt=(LinearLayout)findViewById(R.id.alltablell);
    //for(int f=0;f<mjsonlength;f++){

        for( ind=0;ind<indextitle.size();ind++)
        {

            TextView indextv=new TextView(SubProducts.this);
            indextv.setBackgroundResource(R.drawable.greenbg);
            indextv.setHeight(25);
            indextv.setWidth(50);
            indextv.setId(6);
            indextv.setTextColor(Color.WHITE);
            indextv.setText(indextitle.get(ind));
            indextv.setPadding(20,10,6,3);
            indextr.addView(indextv);

            indextl.addView(indextr,6);

            sv=new ScrollView(SubProducts.this);
             tl=new TableLayout(SubProducts.this);
             for( i=0;i<mjsonlength;i++){
                    tr=new TableRow(SubProducts.this);

                    if(ind==i)  {

                        RelativeLayout rl=new RelativeLayout(SubProducts.this);
                        Resources res = getResources(); //resource handle
                          rl.setBackgroundResource(R.drawable.prd_box);

                         RelativeLayout.LayoutParams newParams1 = new RelativeLayout.LayoutParams(
                                    RelativeLayout.LayoutParams.WRAP_CONTENT,
                                    RelativeLayout.LayoutParams.WRAP_CONTENT);

                            image=new ImageView(SubProducts.this);
                            image.setLayoutParams(newParams1);
                            image.setId(1);
                            image.setImageBitmap(bmp);
                            image.setPadding(5, 20, …
Run Code Online (Sandbox Code Playgroud)

android android-layout

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

类级别字段声明中的private关键字是否实际执行了任何操作?

我正在重构一堆由不同的人编写的课程,这些课程没有一致的标准.在此过程中,我开始思考这些声明之间是否有任何区别:

public class foo(){

    int fooBar = 1;

    ......
Run Code Online (Sandbox Code Playgroud)

public class foo(){

    private int fooBar = 1;

    ......
Run Code Online (Sandbox Code Playgroud)

请注意,这是一个语义问题,我完全了解范围,封装等问题.问题是,在类字段中使用私有范围注释做了什么吗?

谢谢你的所有想法..

(PS.我目前的理解水平说没有区别)

java

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

尝试在复合布局中对齐RadioGroup中的单选按钮

我有这个布局片段.为什么两个无线电组不对齐?我已尝试过使用和不使用边距和填充RadioGroup.

我假设marginLeft从单选按钮本身的左边缘开始marginRight测量,并从最长的单选按钮标题的右侧开始测量.在这方面,文件并不清楚.

请注意,我删除了与布局无关的任何行(例如文本).所有文字大小都是15sp.

    <RelativeLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <ImageView
                android:id="@+id/lengthImage"
                android:layout_centerVertical="true"
                android:paddingLeft="10dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

        <TextView
                android:text="@string/length"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@id/lengthImage"
                android:paddingLeft="15dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

        <RadioGroup
                android:orientation="vertical"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="200dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

            <RadioButton
                    android:id="@+id/lengthMetres"
                    android:paddingRight="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>

            <RadioButton
                    android:id="@+id/lengthFeet"
                    android:paddingRight="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
        </RadioGroup>

    </RelativeLayout>

    <RelativeLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <ImageView android:id="@+id/distanceImage"
                android:layout_centerVertical="true"
                android:paddingLeft="10dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

        <TextView
                android:text="@string/distance"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@id/distanceImage"
                android:paddingLeft="15dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

        <RadioGroup
                android:orientation="vertical"
                android:layout_marginLeft="200dp"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

            <RadioButton
                    android:id="@+id/distanceMile"
                    android:paddingRight="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>

            <RadioButton
                    android:id="@+id/distanceKM"
                    android:paddingRight="20dp"
                    android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-layout

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

确定时间戳是否是确切的小时

我需要确定时间戳是否是精确的小时(即它表示没有分钟,秒或毫秒组件的时间) - 仅使用基元.代码每秒被调用几百次,我不想要一个Calendar或其他对象的开销.

我试过这个但是舍入错误导致比较失败.

 float hours = (time / 3600000f);
 boolean isExactHour = hours == (int)hours;
Run Code Online (Sandbox Code Playgroud)

例如,如果time = 1373763600470,则小时= 381601.03125.该时间戳代表今天格林尼治标准时间01:00:00:000,小时数应为381601.

有什么想法快速简单地做到这一点?谢谢!

[编辑]

看起来这比第一眼看上去更复杂(什么时候不是?:)

为清楚起见,我不关心时区,也不关心闰秒.时间戳是通过一种方法生成的,该方法返回前一个午夜 - 即2013年7月13日00:00:00:000今天.然后我计算,对于长数组中的任何时间戳,总是这个初始时间戳加上/减去5分钟的精确倍数.我的目的是确定一个给定的邮票是否是"最重要的时刻".我可能会遇到边缘情况,其中5分钟的倍数与年末重叠,但我可以忍受这些.

java time utc

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

Android并行(同步)图像下载

伙计们请帮助,这很重要.

我需要在不到5分钟的时间内下载大约2000张图像.所以我决定进行并行图像下载.

如果有人可以建议我更好地进行并行下载或告诉我哪里出错了,我真的很感激.

在错误日志中,已完成任务的数量始终是多种...

请帮忙.

我正在使用Artem Zinnatullin的异步任务执行程序

public class AsyncTaskExecutor {

private static final int CORE_POOL_SIZE;
private static final int MAXIMUM_POOL_SIZE;
private static final int KEEP_ALIVE;
private static final TimeUnit TIME_UNIT;

private static final BlockingQueue<Runnable> concurrentPoolWorkQueue;
private static final ThreadFactory concurrentThreadFactory;
    private static final ThreadPoolExecutor concurrentExecutor;

private AsyncTaskExecutor() {}

static {
 CORE_POOL_SIZE = 5;
 MAXIMUM_POOL_SIZE = 128;
 KEEP_ALIVE = 1;
 TIME_UNIT = TimeUnit.SECONDS;

 concurrentPoolWorkQueue = new LinkedBlockingQueue<Runnable>(10);
 concurrentThreadFactory = new AsyncTaskThreadFactory();
 concurrentExecutor = new ThreadPoolExecutor(CORE_POOL_SIZE,MAXIMUM_POOL_SIZE, KEEP_ALIVE, TIME_UNIT, concurrentPoolWorkQueue, concurrentThreadFactory);
} …
Run Code Online (Sandbox Code Playgroud)

java performance multithreading android threadpoolexecutor

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

致命异常:主03-26> 13:09:15.145:E/AndroidRuntime(389):java.lang.RuntimeException:>无法启动活动

我的守则

private static final LatLng AMSTERDAM = new LatLng(52.37518, 4.895439);
    private static final LatLng PARIS = new LatLng(48.856132, 2.352448);
    private static final LatLng FRANKFURT = new LatLng(50.111772, 8.682632);
    private GoogleMap map;
    private LatLngBounds latlngBounds;
    private Button bNavigation;
    private Polyline newPolyline;
    private boolean isTravelingToParis = false;
    private int width, height;


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

        getSreenDimanstions();

        map = ((SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map)).getMap();

        bNavigation = (Button) findViewById(R.id.bNavigation);
        bNavigation.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (!isTravelingToParis)
                {
                    isTravelingToParis …
Run Code Online (Sandbox Code Playgroud)

android google-maps android-fragments

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

列出lambda表达式,为一个特定查询抛出InvalidOperationException

我有这个片段.

List<Frames> FrameList;
Run Code Online (Sandbox Code Playgroud)

其中Frames是一个只包含字符串的类,包括字符串字段"ExerciseID".

...


void GetFramesForExercise(string exerciseID)

    ....

    if (exerciseID == "3.2.2") { 
       Console.Write(""); }  // quick and dirty to add a breakpoint

    if (FramesList[115].ExerciseID.Equals(exerciseID)) { 
       Console.Write(""); } // quick and dirty to add a breakpoint

    frames = (Frames)FramesList.Single(r => r.ExerciseID.Equals(exerciseID));
Run Code Online (Sandbox Code Playgroud)

通过在console.write语句上添加断点,我能够看到exerciseID确实等于"3.2.2"并且FramesList [115]指向一个ID等于"3.2.2"的Exercise实例.指向的实例正确初始化.

为什么我的查询会抛出InvalidOperationException?

c# linq-to-objects

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

自定义SeekBar中的NoSuchMethodException

我创建了SeekBar类的扩展:

package com.simplemathgame;

import android.content.Context;
import android.widget.SeekBar;
import android.widget.TextView;

public class SeekBarPlus extends SeekBar {
    private TextView numberOfDrills;

    public SeekBarPlus(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public void onStartTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub

    }

    public void onStopTrackingTouch(SeekBar seekBar) {
        // TODO Auto-generated method stub

    }

    public void onProgressChanged(SeekBar seekBar, int progress,
            boolean fromUser) {
        // TODO Auto-generated method stub
        numberOfDrills.setText(progress); 
    }

    public void setTextView(TextView textView){
        numberOfDrills = textView;
    }

}
Run Code Online (Sandbox Code Playgroud)

这是xml布局文件:

<?xml version="1.0" encoding="utf-8"?> …
Run Code Online (Sandbox Code Playgroud)

android android-logcat

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