P
P
Pavel Dmitriev2013-12-24 20:21:54
Java
Pavel Dmitriev, 2013-12-24 20:21:54

How to generate a link from an input field?

There is a link like this http://www.example.ru/nickname.png This link is generated on the site by a script and the picture is always different.
I made a "nickname" input field, a "show" button and a WebView to display a picture from the site.
The activation code is

public class MainActivity extends Activity {
    WebView mWebView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mWebView = (WebView) findViewById(R.id.webview);
        // включаем поддержку JavaScript
        mWebView.getSettings().setJavaScriptEnabled(true);
        // указываем страницу загрузки
        mWebView.loadUrl("http://www.example.ru/никнейм.png");        
    }

    private class HelloWebViewClient  extends WebViewClient
    {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            view.loadUrl(url);
            return true;
        }
    }

Can I somehow generate a link after entering a nickname?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Abramov, 2013-12-24
@kivsiak

hang a handler on the show button.
in the handler, take the value from the input field.
String url = " example.com " + URLEncoder.encode(nickname, "utf-8");
mWebView.loadUrl(url);
how to hang handlers and get the value of text fields can be found in the official documentation. Keywords Button EditText findViewById

P
Pavel Dmitriev, 2013-12-28
@klieve

I solved the problem in this way, although it opens here in the system browser, and not in the web view

public class MainActivity extends Activity implements OnClickListener {

    EditText nick;
    Button SeeGraph;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        //находим элементы
        SeeGraph = (Button) findViewById(R.id.buttonSeeGraph);
        nick = (EditText)findViewById(R.id.nickname);
        // прописываем обработчик
        SeeGraph.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) 
    {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse ("http://example.com" + nick.getText().toString() +".png")));
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question