例如。 “ http://www.john.com/” +“活动中的文本视图内容”
我尝试了很多不同的编码,但是我无法使其工作。我找到的最接近该解决方案的是Google搜索查询的代码,并且我尝试根据自己的需要修改该代码,但这没用。
我有一个名为“ article”的文本视图,该视图的值是从数据库中获取的。假设输出值变为“ 4545”,所以当我单击一个按钮时,我希望浏览器打开并从该URL“ http://www.john.com/4545”开始。
我真的很乐意提供帮助!提前致谢!
MainActivity.java
package com.example.lindstreamerss.androidsqlitesearch;
import android.app.SearchManager;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView textViewInput;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textViewInput = (TextView) findViewById(R.id.article);
public void onSearchClick(View v) {
try {
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
String term = textViewInput.getText().toString();
intent.putExtra(SearchManager.QUERY, term);
startActivity(intent);
} catch (Exception e) {
// TODO: handle exception
}
}
}
layout_item.xml
<TextView
android:id="@+id/article"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="28dp"
android:fontFamily="@font/regular"
android:gravity="center_vertical|start"
android:text="4545"
android:textAllCaps="false"
android:textSize="19sp">
<requestFocus />
</TextView>
<Button
android:id="@+id/imageButton"
android:background="@color/white"
android:fontFamily="@font/regular"
android:drawableLeft="@drawable/ic_web"
android:paddingLeft="25dp"
android:textSize="15sp"
android:textAllCaps="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onSearchClick"
android:paddingRight="40dp"
android:text="Visa artikel" />
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lindstreamerss.androidsqlitesearch">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.example.lindstreamerss.androidsqlitesearch.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
答案 0 :(得分:0)
这很简单,只需单击按钮,然后执行以下代码,并进行必要的更改以使其与您兼容。
const net = require('net');
/**
* Server
* --------------------------------------------
*/
const server = net.createServer( connectionListener => {
console.log(`#${process.pid} Server: client connected`);
connectionListener.on('end', () => {
console.log(`#${process.pid} Server: client disconnected`);
});
connectionListener.write('Hello\r\n');
connectionListener.on('data', data => {
console.log(`#${process.pid} Server: client sends: ${data.toString()}`);
connectionListener.write('Data recieved');
});
});
server.on('error', (err) => {
console.log(err);
server.close();
});
server.listen('/tmp/socket.s', () => {
console.log(`#${process.pid} Server: server bound`);
});
process.on('exit', code => {
console.log(code);
server.close();
});
process.on('SIGTERM', () => server.close() );
process.on('SIGINT', () => server.close() );
答案 1 :(得分:0)
要从其他XML导入的解决方案:
View inflatedView = getLayoutInflater().inflate(R.layout.YOURLAYOUT, null);
TextView text = (TextView) inflatedView.findViewById(R.id.YOURID); String
escapedQuery = text.getText().toString(); Uri uri =
Uri.parse("https://www.YOURWEBSITE.com/" + escapedQuery); Intent intent = new
Intent(Intent.ACTION_VIEW, uri); startActivity(intent);
如果您使用的是ViewHolder(在我的情况下是RecyclerView:
String example = ((TextView) recyclerView.findViewHolderForAdapterPosition(0).itemView.findViewById(R.id.YOURID)).getText().toString();
Uri uri = Uri.parse("https://www.YOURWEBSITE.com/" + example);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
快乐编码;)