Asked  7 Months ago    Answers:  5   Viewed   27 times

How can I do something like a FlowLayout in Android?

 Answers

55

If you watch the talk I gave at the Devoxx University day (available on parleys.com) you will learn how to do it yourself. During the talk I wrote a FlowLayout implementation live on stage to show how simple it is to write custom layouts.

The implementation is hosted here.

Tuesday, June 1, 2021
 
NewPHP
answered 7 Months ago
21

You'd have to use dynamic SQL if you want to do it dynamically like that. Would mean anything you want to execute under the context of that DB, you'd need to include in the dynamic SQL statement too.

i.e. assume you want to list all the tables in MainDB:

This won't work, as the USE statement is in a different context - once that EXECUTE has run, the following SELECT will NOT be running in that same context and so won't be running in MainDb (unless the connection was already set to MainDb)

DECLARE @DatabaseName NVARCHAR(MAX)
SET @DatabaseName = 'MainDb'
EXECUTE('USE ' + @DatabaseName) -- SQL injection risk!
SELECT name FROM sys.tables

So you'd need to do:

DECLARE @DatabaseName NVARCHAR(MAX)
SET @DatabaseName = 'MainDb'
EXECUTE('USE ' + @DatabaseName + ';SELECT name FROM sys.tables') -- SQL injection risk!

Of course, you need to be very careful with SQL injection, for which I point you to the link in Barry's answer.

To prevent SQL Injection, you could also use QUOTENAME() function, it wraps parameter in square brackets:

DECLARE @DatabaseName sysname = 'MainDb'
    , @SQL NVARCHAR(MAX);

SET @SQL = N'USE ' + QUOTENAME(@DatabaseName);

PRINT(@SQL);
-- USE [MainDb]

EXECUTE(@SQL);
Saturday, June 19, 2021
 
revive
answered 6 Months ago
22

Use:

editText.addTextChangedListener(
    new TextWatcher() {
        @Override public void onTextChanged(CharSequence s, int start, int before, int count) { }
        @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { }

        private Timer timer = new Timer();
        private final long DELAY = 1000; // Milliseconds

        @Override
        public void afterTextChanged(final Editable s) {
            timer.cancel();
            timer = new Timer();
            timer.schedule(
                new TimerTask() {
                    @Override
                    public void run() {
                        // TODO: Do what you need here (refresh list).
                        // You will probably need to use
                        // runOnUiThread(Runnable action) for some
                        // specific actions (e.g., manipulating views).
                    }
                },
                DELAY
            );
        }
    }
);

The trick is in canceling and rescheduling Timer each time, when text in EditText gets changed.

For how long to set the delay, see this post.

Sunday, August 8, 2021
 
Zach
answered 4 Months ago
54

Set your compileSdkVersion 'android-P' and targetSdkVersion 28

EDIT: Now compileSdkVersion 28 should also work meaning you no longer have to set it to android-P

Saturday, September 18, 2021
 
oroshnivskyy
answered 3 Months ago
70

Purely by guessing, I changed the following in my gradle config

from:

  testOptions {
    execution 'ANDROID_TEST_ORCHESTRATOR'
  }

to

  testOptions {
    execution 'ANDROIDX_TEST_ORCHESTRATOR'
  }

and all seems to work.

Sunday, September 19, 2021
 
Shevek
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share