安卓:preloaded数据库表布局视图 [英] Android: Preloaded Database to table layout view

查看:215
本文介绍了安卓:preloaded数据库表布局视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林卡住试图找出如何拉从我的pre-填充数据库是我的资产文件夹中tablelayout视图中显示的信息。如果您知道任何明确的教程,或者如果你知道如何做到这一点请你帮助我。

我的意思例如:

数据库例如:

 山区小流域河流海洋

Vermount是否是否

肯塔基否是是

南达科他州是否否否

(在应用程序中,如果我是显示一个特定的行那么tablelayout应该会出现类似这样的)

TableLayout查看

 南达科他州<  - (我知道如何把报头)      是山
      山谷没有
      里弗斯没有
      没有海洋


解决方案

我必须做同样的事情,但并不需要一个游标。以下是我终于实现了我的项目。这需要在显示的无限进度微调的对话框。

 私有类AsyncPop扩展的AsyncTask<对话,整型,滚动型>
{
    @覆盖
    保护无效onPostExecute(滚动型结果)
    {
        的setContentView(结果);
        super.onPostExecute(结果);
    }    @覆盖
    保护滚动型doInBackground(对话... PARAMS)
    {
        对话D = PARAMS [0];        连接CON = StaticDBHelper.getCon(TabActivityDetail.this.getParent());
        声明ST = NULL;        清单<&时间戳GT;日期=新的ArrayList<&时间戳GT;();
        清单<串GT;文本=新的ArrayList<串GT;();
        尝试
        {
            ST = con.createStatement();
            SQL字符串=从activityDateTime递减xfu_ActivityDetail为了选择activityDateTime,detailText
            st.execute(SQL);
            结果集RS = st.getResultSet();            而(rs.next())
            {
                date.add(rs.getTimestamp(activityDateTime));
                text.add(rs.getString(detailText));
            }
            rs.close();        }
        赶上(的SQLException E)
        {
            //不能做了一大堆关于它的现在,应该登录
        }
        最后
        {
            如果(NULL!= ST)
            {
                尝试
                {
                    st.close();
                }
                赶上(的SQLException E)
                {
                    //不理会它,应该登录
                }
            }
        }
        //格式化
        ViewGroup.LayoutParams textBoxp1 =新ViewGroup.LayoutParams(130 ViewGroup.LayoutParams.WRAP_CONTENT);
        ViewGroup.LayoutParams textBoxp2 =新ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        TableRow.LayoutParams rowp1 =新TableRow.LayoutParams(130 TableRow.LayoutParams.WRAP_CONTENT);
        TableRow.LayoutParams rowp2 =新TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
                TableRow.LayoutParams.WRAP_CONTENT);
        TableLayout.LayoutParams表1 =新TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT,
                TableLayout.LayoutParams.FILL_PARENT);        TableLayout的tableView =新TableLayout(_context);
        tableView.setLayoutParams(表1);
        如果(date.size()== 0)
        {
            TextView的dateView =新的TextView(_context);
            dateView.setText(没有活动的详细信息菱给定过滤器);
            dateView.setTypeface(Typeface.DEFAULT,Typeface.BOLD);            连续的TableRow =新的TableRow(_context);
            row.setLayoutParams(新的LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
            row.addView(dateView);
            tableView.addView(行,新TableLayout.LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));
        }
        其他
        {
            对于(INT指数= -1;指数< date.size();指数++)
            {
                连续的TableRow =新的TableRow(_context);
                TextView的dateView =新的TextView(_context);
                TextView中的TextView =新的TextView(_context);                如果(指数== -1)
                {
                    dateView.setText(日期/时间);
                    textView.setText(详细文本);
                    dateView.setTypeface(Typeface.DEFAULT,Typeface.BOLD);
                    textView.setTypeface(Typeface.DEFAULT,Typeface.BOLD);
                }
                其他
                {
                    dateView.setText(LoaderV5._fm.format(date.get(索引)));
                    textView.setText(text.get(指数));
                }
                dateView.setLayoutParams(textBoxp1);
                textView.setLayoutParams(textBoxp2);                row.setLayoutParams(rowp2);
                row.addView(dateView,rowp1);
                row.addView(TextView的,rowp2);
                tableView.addView(行,表1);
            }
        }
        //tableView.setColumnShrinkable(1,真);        Horizo​​ntalScrollView otherscroller =新Horizo​​ntalScrollView(_context);
        otherscroller.addView(的tableView);        滚动型滚轮=新的滚动型(_context);
        scroller.addView(otherscroller);
        scroller.setHorizo​​ntalScrollBarEnabled(真);        d.dismiss();
        返回卷轴;
    }
}

Im stuck trying to figure out how to pull the information from my pre-populated database that is in my assets folder to display in a tablelayout view. If you know of any clear tutorials or if you know how to do it could you please help me out.

Example of what I mean:

Database example:

            Mountains      Valleys    Rivers      Oceans

Vermount yes no yes no

kentucky no yes yes no

South Dakota yes no no no

(In the app if I was to display a specific row then the tablelayout should appear like this)

TableLayout View

           South Dakota         <--(I know how to put the header)

      Mountains       yes
      Valleys          no
      Rivers           no
      Oceans           no

解决方案

I had to do something similar, but didn't need a cursor. Here is what I ended up doing for my project. It takes in a dialog that displays the infinite progress spinner.

private class AsyncPop extends AsyncTask<Dialog, Integer, ScrollView>
{
    @Override
    protected void onPostExecute( ScrollView result )
    {
        setContentView( result );
        super.onPostExecute( result );
    }

    @Override
    protected ScrollView doInBackground( Dialog... params )
    {
        Dialog d = params[0];

        Connection con = StaticDBHelper.getCon( TabActivityDetail.this.getParent() );
        Statement st = null;

        List<Timestamp> date = new ArrayList<Timestamp>();
        List<String> text = new ArrayList<String>();
        try
        {
            st = con.createStatement();
            String sql = "select activityDateTime, detailText from xfu_ActivityDetail order by activityDateTime desc";
            st.execute( sql );
            ResultSet rs = st.getResultSet();

            while( rs.next() )
            {
                date.add( rs.getTimestamp( "activityDateTime" ) );
                text.add( rs.getString( "detailText" ) );
            }
            rs.close();

        }
        catch( SQLException e )
        {
            //Can't do a whole lot about it right now, should log
        }
        finally
        {
            if( null != st )
            {
                try
                {
                    st.close();
                }
                catch( SQLException e )
                {
                    //Just ignore it, should log
                }
            }
        }
        //Formatting
        ViewGroup.LayoutParams textBoxp1 = new ViewGroup.LayoutParams( 130, ViewGroup.LayoutParams.WRAP_CONTENT );
        ViewGroup.LayoutParams textBoxp2 = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT );
        TableRow.LayoutParams rowp1 = new TableRow.LayoutParams( 130, TableRow.LayoutParams.WRAP_CONTENT );
        TableRow.LayoutParams rowp2 = new TableRow.LayoutParams( TableRow.LayoutParams.FILL_PARENT,
                TableRow.LayoutParams.WRAP_CONTENT );
        TableLayout.LayoutParams table1 = new TableLayout.LayoutParams( TableLayout.LayoutParams.FILL_PARENT,
                TableLayout.LayoutParams.FILL_PARENT );

        TableLayout tableView = new TableLayout( _context );
        tableView.setLayoutParams( table1 );
        if( date.size() == 0 )
        {
            TextView dateView = new TextView( _context );
            dateView.setText( "No activity details availible for given filter" );
            dateView.setTypeface( Typeface.DEFAULT, Typeface.BOLD );

            TableRow row = new TableRow( _context );
            row.setLayoutParams( new LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT ) );
            row.addView( dateView );
            tableView.addView( row, new TableLayout.LayoutParams( LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT ) );
        }
        else
        {
            for( int index = -1; index < date.size(); index++ )
            {
                TableRow row = new TableRow( _context );
                TextView dateView = new TextView( _context );
                TextView textView = new TextView( _context );

                if( index == -1 )
                {
                    dateView.setText( "Date / Time" );
                    textView.setText( "Detail Text" );
                    dateView.setTypeface( Typeface.DEFAULT, Typeface.BOLD );
                    textView.setTypeface( Typeface.DEFAULT, Typeface.BOLD );
                }
                else
                {
                    dateView.setText( LoaderV5._fm.format( date.get( index ) ) );
                    textView.setText( text.get( index ) );
                }
                dateView.setLayoutParams( textBoxp1 );
                textView.setLayoutParams( textBoxp2 );

                row.setLayoutParams( rowp2 );
                row.addView( dateView, rowp1 );
                row.addView( textView, rowp2 );
                tableView.addView( row, table1 );
            }
        }
        //tableView.setColumnShrinkable( 1, true );

        HorizontalScrollView otherscroller = new HorizontalScrollView( _context );
        otherscroller.addView( tableView );

        ScrollView scroller = new ScrollView( _context );
        scroller.addView( otherscroller );
        scroller.setHorizontalScrollBarEnabled( true );

        d.dismiss();
        return scroller;
    }
}

这篇关于安卓:preloaded数据库表布局视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆