Type parameter bound for T in
fun <T : ListAdapter!> setAdapter
(adapter: T!)
: Unit where T : Filterable!
is not satisfied: inferred type FlightSearch.FlightSearchAdpater! is not a subtype of Filterable
这是我做什么
var adapter = FlightSearchAdpater(this@FlightSearch, list)
beforflightDepbgwlist.adapter = adapter
autoCompleteTextView.threshold=0
autoCompleteTextView.setAdapter(adapter)
主要活动
class FlightSearch : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_flight_search)
}
fun getflightsearchresult(view:View){
val FlightNumber=flightnumbertext.text.toString()
val url = "/flight/list.json?query="+FlightNumber+""
Arr().execute(url)
}
inner class Arr : AsyncTask<String, String, String>() {
override fun onPreExecute() {
super.onPreExecute()
}
// for build connection
override fun doInBackground(vararg url: String?): String {
var text: String
val connection = URL(url[0]).openConnection() as HttpURLConnection
connection.connectTimeout = 700
try {
connection.connect()
text = connection.inputStream.use { it.reader().use { reader -> reader.readText() } }
} finally {
connection.disconnect()
}
return text
}
override fun onPostExecute(result: String?) {
super.onPostExecute(result)
handleJson(result)
}
override fun onProgressUpdate(vararg text: String?) {
}
@SuppressLint("WrongViewCast")
private fun handleJson(jsonString: String?) {
val jsonObj = JSONObject(jsonString)
val result = jsonObj.getJSONObject("result")
val response = result.getJSONObject("response")
// MaterText.text=mater
// val data = arrivals.getJSONObject("data")
val jsonArray = JSONArray(response.get("data").toString())
val list = ArrayList<FlightShdu>()
var x = 0
while (x < jsonArray.length()) {
val jsonObject = jsonArray.getJSONObject(x)
list.add(
FlightShdu(
jsonObject.getJSONObject("identification").getJSONObject("number").getString("default"),
jsonObject.getJSONObject("airline").getString("name"),
jsonObject.getJSONObject("status").getJSONObject("generic").getJSONObject("status").getString("text"),
jsonObject.getJSONObject("airline").getJSONObject("code").getString("icao"),
jsonObject.getJSONObject("time").getJSONObject("scheduled").getString("arrival"),
jsonObject.getJSONObject("airport").getJSONObject("origin").getJSONObject("code").getString("iata"),
jsonObject.getJSONObject("aircraft").getJSONObject("model").getString("code"),
// for more information
jsonObject.getJSONObject("time").getJSONObject("real").getString("departure"),
jsonObject.getJSONObject("time").getJSONObject("estimated").getString("arrival"),
// jsonObject.getJSONObject("flight").getJSONObject("time").getJSONObject("estimated").getString("arrival"),
jsonObject.getJSONObject("aircraft").getString("registration"),
jsonObject.getJSONObject("status").getJSONObject("generic").getJSONObject("status").getString("diverted"),
response.getString("timestamp"),
jsonObject.getJSONObject("status").getString("icon")
)
)
x++
}
list.forEach(::println)
var adapter = FlightSearchAdpater(this@FlightSearch, list)
beforflightDepbgwlist.adapter = adapter
autoCompleteTextView.threshold=0
autoCompleteTextView.setAdapter(adapter)
}
}
class FlightSearchAdpater (val context: Context, val list: ArrayList<FlightShdu>): BaseAdapter() {
@SuppressLint("ViewHolder", "NewApi", "WrongViewCast")
override fun getView(p0: Int, convertView: View?, parent: ViewGroup?): View {
val view : View = LayoutInflater.from(context).inflate(R.layout.baghdad_arrivel_list,parent,false)
val list = list[p0]
val LogoAriline = view.findViewById(R.id.logo_image) as ImageView
val status = view.findViewById(R.id.ali_id) as AppCompatTextView
val Airport = view.findViewById(R.id.airportid) as AppCompatTextView
val code = view.findViewById(R.id.code_id) as AppCompatTextView
val TimeFlight = view.findViewById(R.id.time_id) as AppCompatTextView
val checkiflive = view.checkifliveTextId
view.callsign_id.text=list.Callsign
view.airline_id.text=list.Airline
code.text = list.code
view.ali_id.text=list.Stauts
status.text= list.Stauts
TimeFlight.text = getDateTime(list.TimeFlight)
Picasso.with(context).load(Uri.parse("https://www.flightradar24.com/static/images/data/operators/"+status.text.toString()+"_logo0.png"))
.error(R.drawable.logo).into(LogoAriline)
Airport.text= list.Airport
view.model_id.text=list.Model
checkiflive.text=list.IfLive
if (p0 == 0) {
view.checkliveId.setVisibility(View.VISIBLE)
}
if (checkiflive.text == "green") {
view.checkliveId.setVisibility(View.VISIBLE)
}else if(checkiflive.text == "null"){
view.checkliveId.setVisibility(View.INVISIBLE)
}
// if (p0 == 0) {
//
//// رحلات وصلات مسبقلا
// val mAddTaskButton = view.findViewById<TextView>(R.id.btn_click_me)
//
// mAddTaskButton.setOnClickListener {
// val intent = Intent(context, FlightsArrivelBeforBGW::class.java)
// context!!.startActivity(intent)
// }
//
// mAddTaskButton.setVisibility(View.VISIBLE)
//
// }
return view
}
private fun getDateTime(s: String): String? {
try {
val sdf = SimpleDateFormat("EE, MMM d KK:mm a")
val netDate = Date(s.toLong() * 1000)
return sdf.format(netDate)
} catch (e: Exception) {
return e.toString()
}
}
override fun getItem(p0: Int): Any {
return list [p0]
}
override fun getItemId(p0: Int): Long {
return p0.toLong()
}
override fun getCount(): Int {
return list.size
}
}
}