English 中文(简体)
安乐器:预先装上数据库,以提出布局。
原标题:Android: Preloaded Database to table layout view

我无意试图说明如何从我先前有人居住的数据库中提取信息,而这一数据库是我的资产组合者,在表格中显示。 如果你知道任何明确的辅导,或者如果你知道如何做,请帮助我。

我指的是:

数据库实例:

            Mountains      Valleys    Rivers      Oceans

South Dakota 是 否

(在我是否要显示一个具体行文时,表格似乎就象这样)

表L. 观点

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

      Mountains       yes
      Valleys          no
      Rivers           no
      Oceans           no
最佳回答

我不得不做类似的事情,但确实需要一名治疗者。 在此,我结束了对我的项目的工作。 它以显示无限进展的直径为.。

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;
    }
}
问题回答

为什么你们想在表Layout中添加这一句?

Just fetch data from SQLite database and using custom adapter use ListView.

So use Multicolumn ListView to set all values in column type,

Look at Multicolumn ListView in Android

Anders - Multi Column List

我认为,在你能够使用数据库之前,你需要从您的资产中复制数据库。

This question has related content Android: Accessing assets folder sqlite database file with .sqlite extension





相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签