File tree Expand file tree Collapse file tree 4 files changed +58
-0
lines changed
java/com/example/kotlin_qiita_client Expand file tree Collapse file tree 4 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 33 package =" com.example.kotlin_qiita_client" >
44
55 <uses-permission android : name =" android.permission.INTERNET" />
6+
67 <application
78 android : allowBackup =" true"
89 android : icon =" @mipmap/ic_launcher"
910 android : label =" @string/app_name"
1011 android : roundIcon =" @mipmap/ic_launcher_round"
1112 android : supportsRtl =" true"
1213 android : theme =" @style/AppTheme" >
14+ <activity android : name =" .DetailActivity" ></activity >
1315 <activity android : name =" .MainActivity" >
1416 <intent-filter >
1517 <action android : name =" android.intent.action.MAIN" />
Original file line number Diff line number Diff line change 1+ package com.example.kotlin_qiita_client
2+
3+ import androidx.appcompat.app.AppCompatActivity
4+ import android.os.Bundle
5+ import android.webkit.WebView
6+ import android.webkit.WebViewClient
7+
8+ class DetailActivity : AppCompatActivity () {
9+
10+ override fun onCreate (savedInstanceState : Bundle ? ) {
11+ super .onCreate(savedInstanceState)
12+ setContentView(R .layout.activity_detail)
13+ val webView = findViewById<WebView >(R .id.web_view)
14+ val url = intent.getStringExtra(" url" )
15+
16+ // リンクをタップしたときに標準ブラウザを起動させない
17+ webView.webViewClient = WebViewClient ()
18+
19+ // 最初に投稿を表示
20+ webView.loadUrl(url)
21+
22+ // jacascriptを許可する
23+ webView.settings.javaScriptEnabled = true
24+ }
25+ }
Original file line number Diff line number Diff line change 11package com.example.kotlin_qiita_client
22
33import android.content.Context
4+ import android.content.Intent
45import androidx.appcompat.app.AppCompatActivity
56import android.os.Bundle
67import android.text.TextUtils
@@ -29,6 +30,7 @@ class MainActivity : AppCompatActivity() {
2930
3031 val listView = findViewById<ListView >(R .id.list_view) as ListView
3132 listView.adapter = mAdapter
33+ listView.onItemClickListener = OnItemClickListener ()
3234
3335 val editText = findViewById<EditText >(R .id.edit_text) as EditText
3436 editText.setOnKeyListener(OnKeyListener ())
@@ -102,4 +104,19 @@ class MainActivity : AppCompatActivity() {
102104 return true
103105 }
104106 }
107+
108+ private inner class OnItemClickListener : AdapterView .OnItemClickListener {
109+ override fun onItemClick (
110+ adapterView : AdapterView <* >? ,
111+ view : View ? ,
112+ position : Int ,
113+ id : Long
114+ ) {
115+ val intent = Intent (this @MainActivity, DetailActivity ::class .java)
116+ // タップされた行番号のデータを取り出す
117+ val result: Item ? = mAdapter.getItem(position)
118+ intent.putExtra(" url" , result?.url)
119+ startActivity(intent)
120+ }
121+ }
105122}
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" utf-8" ?>
2+ <androidx .constraintlayout.widget.ConstraintLayout xmlns : android =" http://schemas.android.com/apk/res/android"
3+ xmlns : app =" http://schemas.android.com/apk/res-auto"
4+ xmlns : tools =" http://schemas.android.com/tools"
5+ android : layout_width =" match_parent"
6+ android : layout_height =" match_parent"
7+ tools : context =" .DetailActivity" >
8+
9+ <WebView xmlns : android =" http://schemas.android.com/apk/res/android"
10+ android : id =" @+id/web_view"
11+ android : layout_width =" match_parent"
12+ android : layout_height =" match_parent" />
13+
14+ </androidx .constraintlayout.widget.ConstraintLayout>
You can’t perform that action at this time.
0 commit comments